locked
add 4 hours to a datetime value RRS feed

  • Question

  • User564383478 posted

    hi can anyby help me to add 4 hours to the following  datetime value

     

    dimdate4pos = MM & "/" & DD & "/" & YY & " " & HH & ":" & MI & ":" & SS

     

    Tuesday, November 17, 2009 7:03 AM

Answers

  • User-1222245141 posted

    Hi.

    Try this(c# code):-

    DateTime dt =  DateTime.Parse(dimdate4pos);
     
    dt.AddDays(4);
     
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2009 8:05 AM
  • User-952121411 posted

    MM & "/" & DD & "/" & YY & " " & HH & ":" & MI & ":" & SS
     

    This is not too hard to accomplish using a 'DateTime' object.  I assume the values above (MM,DD,YY,HH,MI,SS) are all strings since they are being concatenated together; if not say they are Integer values then even easier - just add the variables directly without quotes in the code below.  What we need to do is place the values in the appropriate constructor overload for a new DateTime value, and then add (4) hours to the object.  The code is below:

    'This DateTime object will use the current calendar year as the 'Year' value, 
    'but you can make it anything you need
    Dim MyDateTime As New DateTime(Now.Year, "MM", "DD", "YY", "MI", "SS")
    'Add (4) hours to the DatTime object above:
    MyDateTime.AddHours(4)

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2009 4:27 PM

All replies

  • User-653955379 posted

    Dim dt as datetime=date4pos.AddHours(4)

    Tuesday, November 17, 2009 7:34 AM
  • User113800555 posted

    Hi

    I advise you to work with the class System.DateTime.


    Ex:

    1. Dim date As System.DateTime = System.DateTime.Now
    2. ' 17/11/2009 10:43:00
    3. date = date.AddHours(4)
    4. ' result in 17/11/2009 14:43:00


    Regards,

    Tuesday, November 17, 2009 7:43 AM
  • User-1222245141 posted

    Hi.

    Try this(c# code):-

    DateTime dt =  DateTime.Parse(dimdate4pos);
     
    dt.AddDays(4);
     
     
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 17, 2009 8:05 AM
  • User-952121411 posted

    MM & "/" & DD & "/" & YY & " " & HH & ":" & MI & ":" & SS
     

    This is not too hard to accomplish using a 'DateTime' object.  I assume the values above (MM,DD,YY,HH,MI,SS) are all strings since they are being concatenated together; if not say they are Integer values then even easier - just add the variables directly without quotes in the code below.  What we need to do is place the values in the appropriate constructor overload for a new DateTime value, and then add (4) hours to the object.  The code is below:

    'This DateTime object will use the current calendar year as the 'Year' value, 
    'but you can make it anything you need
    Dim MyDateTime As New DateTime(Now.Year, "MM", "DD", "YY", "MI", "SS")
    'Add (4) hours to the DatTime object above:
    MyDateTime.AddHours(4)

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 19, 2009 4:27 PM