1

whenever a record is created how to set the time in the Date field time value to 8AM by default.

SELECT CustomerID,
CreatedDate,
DATEADD(Day, 1, CreatedDate) As NextDate 
from TestCustomers

enter image description here

instead of 12AM in NEXTDATE field how can I show 8AM as a default time value

1
SELECT DATEADD(Hour, 8, CAST(CAST(DATEADD(Day, 1, [CreatedDate]) AS DATE) AS DATETIME)) As NextDate

This will basically force the field to 8am on the next day after CreatedDate, regardless of what time of the day is in CreatedDate. What I'm doing here is adding a day to CreatedDate, forcing it back to just a date (so the time part is removed), then forcing it to a DateTime (so it will say it's midnight of the next day) and then adding another 8 hours to make it 8am.

1
SELECT DATEADD(day, DATEDIFF(day, 1, ab.CreatedDate), '09:00:00') as NextDate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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