473,395 Members | 1,466 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,395 software developers and data experts.

DateTime range

Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date
for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill

Nov 17 '05 #1
3 16663
Use the AddDays method.

DateTime date1 = DateTime.Now;
DateTime date2 = date1.AddDays(-5);

--
Tim Wilson
..Net Compact Framework MVP

"Bill" <fh***********@rogers.com> wrote in message
news:We********************@rogers.com...
Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill

Nov 17 '05 #2
date1.Subtract(new TimeSpan(5,0,0,0));

Dale Preston
MCAD, MCDBA, MCSE

"Bill" <fh***********@rogers.com> wrote in message
news:We********************@rogers.com...
Hi

I am trying to get a date range in c#.
I can get the one range by date1 = DateTime.Now();

But if I wanted to go back say 5 days how do I go about calculating the date for that.

I was looking for a DateTime function that would convert the date into an
integer and then convert it back but without luck.

Any suggestions would be appreciated

Thanks in advance

Bill

Nov 17 '05 #3
Have you tried,

DateTime fiveDaysAgo = DateTime.Now().AddDays(-5);

?

Nov 17 '05 #4

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

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
2
by: Maksim Kasimov | last post by:
there are few of a time periods, for example: 2005-06-08 12:30 -> 2005-06-10 15:30, 2005-06-12 12:30 -> 2005-06-14 15:30 and there is some date and time value: 2005-06-11 12:30 what is the...
1
by: Reny J Joseph Thuthikattu | last post by:
Hi, I want to create a a crystal report based on the DAteTime Range.Can any one tell me how do i pass the Values from the VB.NET.I am uasing Crystalreportviewer control My field is isin the...
2
by: John Reese | last post by:
Hi. >>> import time, calendar, datetime >>> n= 1133893540.874922 >>> datetime.datetime.fromtimestamp(n) datetime.datetime(2005, 12, 6, 10, 25, 40, 874922) >>> lt= _ >>>...
8
by: ajs | last post by:
I have a process that verifies that a server is running. If the server stops responding I send an email to a support person. Now I want to add a downtime indicator so that my code does not send...
7
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns "1:59:00 PM" it never returns seconds. Database field...
7
by: crs27 | last post by:
Hai, Im new to sql server... I want to convert a field in a table to DateTime. The column(Column Name-DDateTime , Data type String) has data in this format 01-04-2008 15:12:52 i want...
3
by: shapper | last post by:
Hello, I am checking a DateTime variable to check if in range: low < MyDateTime < high. However, I know need do the same but not care about the year. Can I do this? Thanks, Miguel
14
by: shapper | last post by:
Hello, I have two nullable DateTime: begin and end. I need to find the range, in month, between both variables. If for some reason, for example begin is null, it is not possible to calculate...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.