Groups | Blog | Home
all groups > sql server (microsoft) > june 2005 >

sql server (microsoft) : Inserting current date midnight


kayda
6/16/2005 9:09:17 AM
Hi:

You can INSERT the current date and time like this

SELECT databasefield, getdate()
FROM testtable

but what is the easiest way to SELECT the current date's midnight
timestamp, so instead of SELECTing 6/17/2005 4:17:32 PM it would SELECT
6/17/2005 12:00:00 AM?

Thanks,
Kayda
Jeff Kish
6/16/2005 3:52:52 PM
[quoted text, click to view]
Here is one way:
select cast(convert(char(8), CURRENT_TIMESTAMP, 112) AS datetime)

I got it off of google (in about 5 minutes I hate to say) from:
http://www.karaszi.com/SQLServer/info_datetime.asp#GettingRidOfTimePortion

aaron.kempf NO[at]SPAM gmail.com
6/17/2005 3:35:45 PM
or you can take convert(datetime, convert(int, GETDATE-.5)))

this will basically always round down-- so you actually want to add .5
instead of subtracting it

-aaron
AddThis Social Bookmark Button