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

Date difference

Hi,

I have to know if the passed date to my method is more then 13 months
old then the today's date. How would I do that?

If I do this

TimeSpan dtDiff = dtNow.Subtract(dtSales);
and check dtDiff.Days then it won't be accurate.

Any help will be appreciated.

Thanks

Jun 14 '06 #1
1 1531

MasoodAd...@gmail.com wrote:
Hi,

I have to know if the passed date to my method is more then 13 months
old then the today's date. How would I do that?

If I do this

TimeSpan dtDiff = dtNow.Subtract(dtSales);
and check dtDiff.Days then it won't be accurate.


Well observed; because a TimeSpan is just a number of days; it doesn't
understand months. The only relevant thing that understands months is
DateTime itself, so we must look to that.

If we consider dtNow.AddMonths(-13), that is the cutoff date we are
interested in, with all the month calculations handled for us. DateTime
overloads the comparison operators, so we are done.

--
Larry Lard
Replies to group please

Jun 14 '06 #2

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

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
5
by: tamilan71 | last post by:
Hello All I have table with following fields: GroupId VisitDate 1 10/19/1993 1 11/24/1998 2 10/18/1993 2 10/29/1998 3 ...
7
by: Edward Mitchell | last post by:
I have a number of DateTimePicker controls, some set to dates, some set to a format of Time. The controls are all embedded in dialogs. I created the controls by dragging the DateTime picker from...
16
by: Atley | last post by:
I am trying to get a overall difference on two dates, I can get the difference in Years, Months, Weeks, Days, Hours, Minutes, Seconds, no problems... What I cannot seem to figure out is how to...
6
by: Scott | last post by:
I have a start date and an end date in my project that is defaulted to the current date at run-time using the following code... Date1.Value = Now() Date2.Value = Now() I then have some code...
13
by: priyasmita_guha | last post by:
Here is a program- /* PROGRAM: To find the difference between two dates */ #include<dos.h> #include<stdio.h> #include<conio.h> #include<process.h> void valid_date(int,int,int); int...
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
3
by: bbawa1 | last post by:
Hi, I have a table which has a field ItemsReceived of type datetime. I have a grid view which has two columns. In first column i have to show the data from field ItemsReceived and in second...
7
by: rdawadiuk | last post by:
hi, I would like to calculate the date difference between two dates using field names which I have in my table. The field name is " Account opened on" for eg If the "Account open on" is Jan 5,...
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.