how to read the records from database that have today's date using select statement.
I have tried doing this:
DateTime todaysDate = DateTime.Now;
string qr = String.Format(" SELECT tbl_Student.StudentName AS Name
FROM tbl_StudentTrack
LEFT JOIN tbl_Student ON tbl_Student .Id=tbl_StudentTrack .StudentId
WHERE UserId = {0} ", userID, todaysDate);
But this doesnt seem to work, it just displays all the records.
Loading
Guest UserPosted May 11, 2015, 10:45 AM
Something like this should work:
SELECT * FROM StudentTrack
WHERE CAST(GETDATE() AS DATE) = CAST(YourDateColumn AS DATE)
Pranay RanaPosted May 11, 2015, 1:02 PM
if you want to get record created today there are two way to do it
1) using gatedate function of sql
SELECT tbl_Student.StudentName AS Name
FROM tbl_StudentTrack
LEFT JOIN tbl_Student ON tbl_Student .Id=tbl_StudentTrack .StudentId
WHERE UserId = {0} and CONVERT(VARCHAR(10), datecolumn, 111) = CONVERT(VARCHAR(10), GETDATE(), 111)
2) passing through code
string date = String.Format("{0:yyyy/MM/dd/}", DateTime.Now);
string qr = String.Format("SELECT tbl_Student.StudentName AS Name
FROM tbl_StudentTrack
LEFT JOIN tbl_Student ON tbl_Student .Id=tbl_StudentTrack .StudentId
WHERE UserId = {0} and CONVERT(VARCHAR(10), datecolumn, 111) = {1}", userID, todaysDate);