evci
asked on
C# Adjust DateTime based on Input Parameter
Hi ... need your help with a DateTime issue. I have a script that runs via a job scheduler. When the 'job' kicks off, it passes the appropriate DateTime (it is not always NOW. The script runs 24 hours a day at the top of the hour. Sometimes a job is delayed by 15 minutes to 45 minutes, but will always use the top of the hour time).
The DateTime are passed automatically to my script via @@startDateTime@@ and @@endDateTime@@. The format of these two parameters are "yyyy-MM-dd 00:00".
Assume
@@startDateTime@@ = "2016-02-10 10:00"
@@endDateTime@@ = "2016-02-10 10:59"
I need to return newStartDateTime = "2016-02-10 09:00" and newEndDateTime = "2016-02-10 09:59"
The DateTime are passed automatically to my script via @@startDateTime@@ and @@endDateTime@@. The format of these two parameters are "yyyy-MM-dd 00:00".
Assume
@@startDateTime@@ = "2016-02-10 10:00"
@@endDateTime@@ = "2016-02-10 10:59"
I need to return newStartDateTime = "2016-02-10 09:00" and newEndDateTime = "2016-02-10 09:59"
Are you trying to minus an hour in your C# code?
ASKER
Yes. I need to minus an hour.
Hi,
Here it is.
Here it is.
newStartDateTime = dt.AddHours(-1);
newEndDateTime = dt.AddHours(-1);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help. Worked.