-2

I have datetime field as

03/04/2016 08:00:00 AM
03/15/2016 04:00:00 AM

I want to keep it as datetime but set the time to 12am for all entries. So the result should be

03/04/2016 12:00:00 AM
03/15/2016 12:00:00 AM

No tsql or declaring variables.

James Z
  • 12,209
  • 10
  • 24
  • 44
Ruby
  • 5
  • 5
  • 3
    what do you mean "no t-sql"? – Lamak Mar 15 '16 at 16:06
  • Your subject line says pm but the text of the question says am. Please clarify. – Dan Bracuk Mar 15 '16 at 16:11
  • 2
    12:00:00 is PM. 12 AM is midnight and is 00:00:00 as a datetime. – rdbradshaw Mar 15 '16 at 16:23
  • Title says 12PM, question says 12AM. I suspect it's a duplicate of "I just want the date part" – Bridge Mar 16 '16 at 17:15
  • 1
    Possible duplicate of [How to return the date part only from a SQL Server datetime datatype](http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype) – Bridge Mar 16 '16 at 17:15
  • Here is a list of different techniques you could use to manipulate the time. (http://stackoverflow.com/a/202288/16391). If by "no tsql or declaring variables", you mean you want the table to take care of this, you can create a Trigger to address the data before (or immediately after) its put away into the row. – StingyJack Mar 16 '16 at 17:24

1 Answers1

1

Try this:

DATEADD(hour, 12, CAST(CAST(myfield AS Date) AS Datetime))
Giorgos Betsos
  • 71,379
  • 9
  • 63
  • 98
  • 2
    I'm conflicted about upvoting this. I mean, it does what op wants, but I'm still unsure what does the `No t-sql` requirement means – Lamak Mar 15 '16 at 16:33
  • 1
    I take that as meaning something that doesn't work within a single `select`. – shawnt00 Mar 16 '16 at 17:14