none
DateAdd function substract 1 day RRS feed

  • Question

  • Hi guys,

    I have a datastring called "Startdate". I want to to subtract 1 day from this string to create the string "Newdate''. The dateformat of the "Startdate"string is dd-mm-yyyy (01-12-2017).

    I tried to use the DateAdd function like this: Newdate = Dateadd("d",-1,"Startdate"). I think it doesn't work because of the dateformat.

    How can I subtract one day which also results in the format dd-mm-yyyy?

    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:17 PM Unanswerable drive-by question
    Thursday, July 27, 2017 9:30 AM

All replies

  • That all depends on the default date format of your system.

    Use FormatDateTime function to convert date to desired format.

    If you use PowerShell this is not as big of a problem.

    If your dt format is as above:

    startDate = CDate("01-12-2017")
    newdate = DateAdd("d",1,startDate)

    If the date format is other then take the date apart.

    dt = Split(("01-12-2017","-")
    newformat = dt(1) & "-" & dt(0) & "-" & dt(2)

    then use newformat to calc date.


    \_(ツ)_/


    • Edited by jrv Thursday, July 27, 2017 9:45 AM
    Thursday, July 27, 2017 9:39 AM
  • why not use

    $newdate = get-date -date $(get-date).adddays(-1) -format dd-MM-yyyy

    in powershell

    Thursday, July 27, 2017 10:14 AM