Mike Littlewood
asked on
Using GETDATE() to return a date only without time
I need to use (I think) the GETDATE() function to return the current date, but I need to make sure that it is only the date and no time, or at least time to be 0.
Is this the right way to go about it
CONVERT(DateTime, CONVERT(Char, GETDATE(), 103), 103))
or is there a better way
Thanks in advance
Is this the right way to go about it
CONVERT(DateTime, CONVERT(Char, GETDATE(), 103), 103))
or is there a better way
Thanks in advance
this is enough right?, why are u again converting i.e 2 times converting in ur query
select convert(varchar, getdate(), 103)
select convert(varchar, getdate(), 103)
ASKER
Im converting it twice so I get it back in date form of the format 'dd/mm/yyyy 00:00:00' and not something like 'dd/mm/yyyy 12:30:05'
It seems to set the time to 0 which is what I want
It seems to set the time to 0 which is what I want
you can get slight improvement if instead of converting to a char, you convert to integer this will truncate the time portion. If you want you can cast back to datetime, but this will be done explicitly for you anyway if you assign to a datetime variable, or complare to a datetime field etc.
select cast(cast(getdate() as integer) as datetime)
select cast(cast(getdate() as integer) as datetime)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the advice all
absolutely right, sorry for the bum steer
itsvtk