473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get yesterday using datetime...

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...
Nov 15 '05 #1
3 32249
Bavo <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi ,

Try this:

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

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bavo" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
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...

Nov 15 '05 #3
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/
er**@cc.ensoft-software.com [remove the first "CC."]

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bavo <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: KathyB | last post by:
I'm trying to concatenate fields in SQL stored proc for use in text field in asp.net dropdownlist. I'm running into a problem when I try to use a DateTime field, but can't find the answer (so far)...
6
by: ruca | last post by:
How can I define a DatePicker control with events in ASPX? When I drag and drop a DateTime Picker control into my page and then try to use it in code, it gives an error saying that my control is...
4
by: Michael C# | last post by:
Given a DateTime variable, what's the best way to check "minor" status (i.e., less than age 18 years) based on today's date? I came up with this: Dim minor As Boolean = true 'dtDOB is a...
0
by: Vilcoyote | last post by:
Here is the problem. I need to display a date in the en-US format (6:00 PM and not 18:00). Theorically there are many ways to get a short date format string from a date: myDate.ToString("t")...
2
by: Marco Shaw | last post by:
Does DateTime have a built-in feature to just give me "Dec" or similar for "December"? Marco
11
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999...
4
by: pks83 | last post by:
In MSSQL I am using datetime as the column type and trying to execute the below mentioned query select time from tickets where ticket_id = '1'; when i execute the query on sql manager window it...
1
by: Lawrence Pereira | last post by:
Can any one help me in inserting any date into the table using insert command because when i m trying to insert date using insert command the query executes but the date is totally wrong if i am...
5
by: indika | last post by:
Hi, I'm a newbie to python but have some experience in programming. I came across this requirement of using datetime.date objects associated with some another object. eg. a dictionary containing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.