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

difference of dates

I need to calculate the number of days between two dates formatted yyyymmdd.
Besides creating a whole date class, is there a simpler method of doing it?

for example:
20050203 - 20050201 = 2

right now what I have is
string sdate1 = "20050203";
string sdate2 = "20050201";
string date = date1 .substr(6.2);
int ndate1 = atoi(sdate1.c_str());
date = date2 .substr(6.2);
int ndate2 = atoi(sdate2.c_str());
//calculate how many days are missing
days = ndate1 - ndate2 ;

which just gets me the difference between dates without taking into account
month and year and leap year. Any suggestions would be appreciated.

Thanks!
Jul 23 '05 #1
2 2109
Alex wrote:
I need to calculate the number of days between two dates formatted
yyyymmdd. Besides creating a whole date class, is there a simpler
method of doing it?
for example:
20050203 - 20050201 = 2

right now what I have is
string sdate1 = "20050203";
string sdate2 = "20050201";
string date = date1 .substr(6.2);
int ndate1 = atoi(sdate1.c_str());
date = date2 .substr(6.2);
int ndate2 = atoi(sdate2.c_str());
//calculate how many days are missing
days = ndate1 - ndate2 ;

which just gets me the difference between dates without taking into
account month and year and leap year. Any suggestions would be
appreciated.


Calculate Julian Date from year/month/day and then compare the two.
Search the web for Julian Date calculation.

V
Jul 23 '05 #2
Use the header <ctime> and struct tm. Fill out the struct, then use the
functions provided in the header.

- JFA1
Jul 23 '05 #3

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

Similar topics

26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
6
by: Ashish Sheth | last post by:
Hi All, In C#, How can I get the difference between two dates in number of months? I tried to use the Substract method of the DateTime class and it is giving me the difference in TimeSpan,From...
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...
4
by: Yotam | last post by:
Hi, I need some help with JS. I will be grateful, if you can help me out. I have two date fields (check in, check out) and "number of days" field. I want the script to calculate automatically...
2
by: Blackmore | last post by:
I am trying to use javascript to calculate the difference between two form inputted dates and return the result to another form object. When I load up the page with the function on my web browser...
8
by: Claudia Fong | last post by:
Hi, In VB we have DateDiff to calculate the days difference between 2 dates, I was wondering if we have something like that in C#? I want to calculate for example the days difference...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi, misters which the best method for get the difference (in days) of two dates. The hour (hh:mm) don't mind, would be 00:00 for all dates. 1.) fechaUno.Substract(fechaDos).Days 2.)
3
by: prashantkuppa | last post by:
hi, iam struggling with difference between two dates of format type dd/mm/yyyy i need difference between two dates olddate(dd/mm/yyyy) - newdate(dd/mm/yyyy) and this should be in java script...
4
by: sniipe | last post by:
Hi! I am new in Python, so I count for your help. I need to get difference in months between two dates. How to do it in python? I am substracting two dates, for example date1 - date2 and I got...
4
by: lenygold via DBMonster.com | last post by:
I found this example in MYSQL: create table events ( id integer not null primary key , datetime_start datetime not null , datetime_end datetime not null ); insert into events values ( 1,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
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...

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.