How to get Yesterday's date?

code

#1

Hi all,

I’d like to ask if anyone is aware of a simple solution to get yesterday’s date.

So far I’ve been able to split a DateString into three variables to compile them in the following format: “dd.mm.yyyy”

It looks something like this:

  • Day: DateString.ElementAtOrDefault(3) + DateString.ElementAtOrDefault(4)
  • Month: DateString.Remove(2)
  • Year: DateString.ElementAtOrDefault(6) + DateString.ElementAtOrDefault(7) + DateString.ElementAtOrDefault(8) + DateString.ElementAtOrDefault(9)

My date variable then consists of:

  • Day + “.” + Month + “.” + Year

The problem I’m currently facing is in finding an easy way to also get yesterday’s date in the same format.

Any ideas?
Thanks!


How to calculate next day from a date input variable?
#2

Did you try

now.AddDays(-1).ToShortDateString.Replace("/",".")

or

now.AddDays(-1).ToString(“dd.MM.yyyy”)


#3

In assign use System.DateAdd(“d”,-1,(System.DateTime.Today))

DateAdd is the VB function which used to increase or decrease date or time.

For more information on DateAdd click this link: https://msdn.microsoft.com/en-us/library/c0ccadae(v=vs.110).aspx


#4

Thank you! this solved my issue in a much easier fashion!


#5

How to add date and time?