Converting GetDate() to current date with a specific time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrPogle
    New Member
    • Aug 2007
    • 1

    Converting GetDate() to current date with a specific time

    I want to return the the date for the day before my query runs but at a specific time. The time is not midnight, so:

    convert(varchar (19),getdate() and '08:00:00',101)

    does not work. Instead I want to return the day before at 8am.

    Thanks.
  • azimmer
    Recognized Expert New Member
    • Jul 2007
    • 200

    #2
    Originally posted by MrPogle
    I want to return the the date for the day before my query runs but at a specific time. The time is not midnight, so:

    convert(varchar (19),getdate() and '08:00:00',101)

    does not work. Instead I want to return the day before at 8am.

    Thanks.
    Code:
    convert(datetime,left(convert(varchar, getdate(), 121),4+1+2+1+2) + ' 08:00')

    Comment

    • DaveStarns
      New Member
      • Dec 2017
      • 1

      #3
      Code:
      (dateadd(hour,8(dateadd(day,-1,convert(datetime,convert(date,getdate()),102)))))

      Comment

      Working...