Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL datetime needs to read 00:00:00.000

I have the following piece of SQL:

select DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

which comes through as this format:

2012-02-29 23:59:59.000

I need the exact piece of code with the date the same, however the time part must read 00:00:00.000

Modify* I should have been clear here: I need to have the last day of previous month at any given time (with the time in 00:00:00.000 format of course)

like image 490
JsonStatham Avatar asked Mar 29 '12 10:03

JsonStatham


People also ask

How do I remove t00 00 00?

If you don't want to "See" the 00:00:00.000 on your datetime type field, then CAST it to a date when you SELECT from the table.

What is the format for datetime in SQL?

SQL Date Data Types DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS. YEAR - format YYYY or YY.

What is time 0 SQL Server?

The hour value of 0 represents the hour after midnight (AM), regardless of whether AM is specified. PM cannot be specified when the hour equals 0. Hour values from 01 through 11 represent the hours before noon if neither AM nor PM is specified.


1 Answers

select dateadd(d,datediff(d,0,dateadd(s,-1,dateadd(m,datediff(m,0,getdate()),0))),0)
like image 186
general exception Avatar answered Nov 15 '22 07:11

general exception