473,491 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DateTime Substract

Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a
param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays,
right?!

Thanks,
Cezar
Nov 18 '05 #1
3 5869
CBN Media wrote:
Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a
param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays,
right?!


It's almost as simple:

DateTime.Now.AddDays( -4)

or

DateTime.Now.Subtract( new TimeSpan( 4, 0, 0, 0))

--
mikeb
Nov 18 '05 #2
DateTime.Now.AddDays(-x);

"CBN Media" <ce***@cbnmedia.com> wrote in message
news:tg*******************@news20.bellglobal.com.. .
Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays,
right?!

Thanks,
Cezar

Nov 18 '05 #3
Ouch, of course :)

Thank you both,

Cezar

"mikeb" <ma************@mailnull.com> wrote in message
news:OD****************@TK2MSFTNGP11.phx.gbl...
CBN Media wrote:
Hi,

I need to calculate a date which is current date (Now) minus x days.
I looked at DateTime, it has a fairly large number of methods to add
something to a date, but for substracting is just Substract which takes as a param a TimeSpan.

Am I looking at the wrong method here? It should be as simple as AddDays, right?!


It's almost as simple:

DateTime.Now.AddDays( -4)

or

DateTime.Now.Subtract( new TimeSpan( 4, 0, 0, 0))

--
mikeb

Nov 18 '05 #4

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

Similar topics

1
2747
by: Ted | last post by:
I would like to format my date "06/08/2003 12:00" to something like "1 day ago" or "24 hours ago". Is there a date format I can use to do this or does anyone have any pointers as to how i could do...
3
4360
by: Hon Seng Phuah | last post by:
Hi all, I have a problem and have someone can help me. I want to substract a numerica from a string. For example: A string is: $line = RVW-30 {
4
2281
by: Jean-Christophe Michel | last post by:
Hi, In a complex merging of two (non ordered) xml files i need to keep track of the elements of the second tree that were already merged with first tree, to copy only unused elements at the end....
7
16211
by: developer | last post by:
I want to substract a number of month from a specific date. someone have a easy solution ? Thanks
4
7694
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
3
1794
by: muntyanu | last post by:
Hi all, I have datetime field in database. When I am getting records older than specific date that I passed in parameter I can not get records that differs only in Time part of the datetime...
1
2020
by: ApocalypSys | last post by:
Hi, I need to substract a variable hour from a timestamp in PostgreSQL 8.2, I think I can use the following sentence select '2007-05-14 12:36:47' + ('-5 hours'::reltime); I try that line in...
9
2214
by: valy | last post by:
hi all, how to open two images and then substract both together to get the different? the image will be a grayscale image. A sequence of image is stored in a folder. I want to open two images and...
9
2367
by: Francois Grieu | last post by:
Is it OK to substract two pointer-to-void ? Are they guaranteed to act as pointer-to-char ? I fail to find that discussed in ISO/IEC 9899:1999. In other words (hopefully), is the following...
0
7115
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,...
0
7154
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
7190
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...
1
6858
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...
1
4881
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...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
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...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.