July 15, 2004 at 3:34 pm
I need to compare two dates in the stored procedure: one is datetime that gets value from the system by getDate() function and another is from the database.
Both values have format "MMM DD YYYY HH:MM", but the system datetime gives current HH:MM, when the database values have 00:00.
I don't care about time, I just want to compare the dates.
Question: Is there a simple way to convert these datetime values into the plain date format "MM/DD/YYYY"?
Thank you for the help
July 15, 2004 at 4:41 pm
Simplest way I know is as follows:
cast(floor(cast(getdate() as float)) as datetime)
This will give the current date with no time.
July 15, 2004 at 4:57 pm
Also you can use,
convert(varchar(10),getdate(),101) = convert(varchar(10),'07/15/2004',101)
July 15, 2004 at 5:05 pm
Well, thanks for the help. I'm almost there.
Just tried these functions. They produced date with time "12:00 am". But the dates I have in my database have time "00:00".
So, I need to figure out how to set time to "00:00" to be able to compare the values.
July 15, 2004 at 5:12 pm
You can use:
SET DATEFORMAT mdy
This doesn't affect the way the date is stored in SQL server, only how it is displayed.
July 15, 2004 at 6:37 pm
Thanks everybody for the help!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply