Avatar of evci
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"
C#

Avatar of undefined
Last Comment
evci
Avatar of dinesh manikkam
dinesh manikkam

Are you trying to minus an hour in your C# code?
Avatar of evci
evci

ASKER

Yes. I need to minus an hour.
Avatar of thiyagu murug
thiyagu murug

Hi,

Here it is.
newStartDateTime = dt.AddHours(-1);
newEndDateTime = dt.AddHours(-1);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of evci
evci

ASKER

Thanks for the help.  Worked.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo