Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how i can retrieve rows by specific date in sql server?

I'm working in project for by PHP and SQL Server.

The owner want from me design page show only users who register in same day

i.e., if today 11-3-2011 i want show only all users who register in 11-3-2011

The table is:

id  username  date

1   john      11\3\2011
2   sara      11\3\2011
3   john      5\1\2011
4   kreem     1\2\2011

i make it by mysql

where DATE_ADD( items.created_date, INTERVAL 1 DAY ) > NOW() 

this cable of code show data which only insert in same day thats mean if today 10-4-2011 it will show only data which insert in 10-4-2011 if i today 15-4-2011 and im dose not insert any thing it will not show any thing, how i can build code like this in sql server? hope to be my question clear and understand

like image 923
user700792 Avatar asked Dec 12 '22 14:12

user700792


1 Answers

select id, userName
from YourTable
where CAST(date AS DATE) = CAST(GETDATE() AS DATE)

Function GETDATE() returns the current date and time.

CAST(column as TYPE) will threat DateTime as just Date to omit differences in Time

like image 190
abatishchev Avatar answered Dec 29 '22 19:12

abatishchev