-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.

6
  • 3
    what do you mean "no t-sql"?
    – Lamak
    Mar 15, 2016 at 16:06
  • Your subject line says pm but the text of the question says am. Please clarify.
    – Dan Bracuk
    Mar 15, 2016 at 16:11
  • 2
    12:00:00 is PM. 12 AM is midnight and is 00:00:00 as a datetime.
    – rdbradshaw
    Mar 15, 2016 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, 2016 at 17:15
  • 1
    Possible duplicate of How to return the date part only from a SQL Server datetime datatype
    – Bridge
    Mar 16, 2016 at 17:15

1 Answer 1

1

Try this:

DATEADD(hour, 12, CAST(CAST(myfield AS Date) AS Datetime))
2
  • 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, 2016 at 16:33
  • 1
    I take that as meaning something that doesn't work within a single select.
    – shawnt00
    Mar 16, 2016 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.