How to get yesterday using datetime...

  • Thread starter Thread starter Bavo
  • Start date Start date
B

Bavo

Hi,

I am trying to work with datetime functions in C#. Can
anyone tell me how to get accurate yesterday using
current datetime?? I want to display yesterday and today
in two differnt text boxes in a web page.

Thanks in advance

Bravo...
 
Hi ,

Try this:

DateTime yesterday = DateTime.Now.AddDays( -1 );

Cheers,
 
Bavo said:
I am trying to work with datetime functions in C#. Can
anyone tell me how to get accurate yesterday using
current datetime?? I want to display yesterday and today
in two differnt text boxes in a web page.

What part of yesterday do you want? I'd suggest starting with
DateTime.Now.AddDays(-1) - that will give you the DateTime exactly one
day earlier than now.
 
Good point, Jon

the AddDays(-1) at on 12/10/2003 at 2:15PM will give 12/9/2003 2:15PM

if you want to get the very BEGINNING then you'll want to look into the
DateTime constructors or even

DateTime.Now.Date.AddDays(-1)


--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(e-mail address removed)-software.com [remove the first "CC."]
 
Back
Top