How to get Yesterday's date?

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!

11 Likes

Did you try

now.AddDays(-1).ToShortDateString.Replace(“/”,“.”)

or

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

19 Likes

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: DateAndTime.DateAdd Method (Microsoft.VisualBasic) | Microsoft Learn

2 Likes

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

How to add date and time?