Get yesterday date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is
there a similar way to do it in vb.Net?

Thanks in advance
 
Hi Li Pang,

You can use the following code:

Dim oTimeSpan As New System.TimeSpan(1,0,0,0)
Dim oDate As System.DateTime = System.DateTime.Now.Substract(oTimeSpan)

and oDate should contain yesterdays date...

Greetings,

Juan Pedro Gonzalez
 
Li Pang,

You mean this?
Dim yesterday As DateTime = Now.AddDays(-1)

I hope this helps,

Cor
 
Li said:
Hi,

In VB6 I used Now() -1 to get yesterday, but it's not allowed in vb.NET. Is
there a similar way to do it in vb.Net?

Thanks in advance

As others have posted, Now.AddDays(-1) is the literal translation of
the VB6 expression Now() - 1.

But if you want *yesterday*, rather than *this time yesterday*, you
should be using Today, not Now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top