473,811 Members | 3,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 16697
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******** ************@ro gers.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******** ************@ro gers.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
9350
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 datetime strftime() methods require year >= 1900 Does anyone know of a datetime string formatter that can handles strftime format strings over the full range that datetime objects support?
2
6497
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 "pythonic" way to check is the date/time value in the given periods range? something like xrange:
1
10932
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 format 2/12/2000 2:04:00 PM Please help me out Reny
2
16223
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= _ >>> datetime.datetime.utcfromtimestamp(n) datetime.datetime(2005, 12, 6, 18, 25, 40, 874922) >>> gmt= _
8
4635
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 mail if the sever has a scheduled downtime say, Sunday at 23:00 for 4 hrs. Is there an easy way to see if the current time is within that window? Thanks
7
13362
by: TheLostLeaf | last post by:
DateTime tTime = DateTime.Now; ------------------------------------------------------------------------------------------- tTime returns "1:59:00 PM" it never returns seconds. Database field is SQL datetime or smalldatetime.
7
12707
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 to get records in a particular datetime range.Do not no how to proced. usually i can write a query like this select DDateTime from table_name where DDateTime between '01/27/2008 01:23:32' and '01/29/2008 01:23:32'
3
1535
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
350
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 the range then I want to define the range as 1 month. How can I do this?
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10384
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10395
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.