473,782 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate days

I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

# include <iostream.h>
# include <conio.h>
void main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();

c_year=year*365 ;
c_month=(month-1)*30;
t_days=c_year+c _month+day;

cout<<"Days from"<<day<<"/"<<month<<"/"<<year<<" to January 1st. 2000:
"<<t_days;
}

Oct 10 '06 #1
8 2414
amackeyb wrote:
I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???
No, it is not. See blow.
>
# include <iostream.h>
Non-standard header. Use <iostream>
# include <conio.h>
Non-standard header, don't know what it does.

using namespace std;
void main()
Undefined Behavior. Main *MUST* return int.
int main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();
you don't need to clear the screen. Kill this line (which
then also lets you remove that conio.h).
>
c_year=year*365 ;
c_month=(month-1)*30;
What about Jan, Feb, Mar, May, Jul, Aug, Oct, and Dec,
which don't have 30 days?
t_days=c_year+c _month+day;

cout<<"Days from"<<day<<"/"<<month<<"/"<<year<<" to January 1st. 2000:
"<<t_days;
cout << endl;
}
Oct 10 '06 #2
red floyd wrote:
>void main()
Undefined Behavior. Main *MUST* return int.
I suspect it's ill-formed syntax. That occurs before any behavior.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Oct 10 '06 #3

"amackeyb" <am******@gmail .comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
>I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???

# include <iostream.h>
#include <iostream>
# include <conio.h>
I wouldn't bother with this, unless you really wanted to.
void main()
{
int month, day, year, c_year, c_month, t_days;

cout<<"Give a date dd/mm/yy: "<<endl;
cout<<"Day: ";
cin>>day;
cout<<"Month: ";
cin>>month;
cout<<"Year: ";
cin>>year;
clrscr();

c_year=year*365 ;
c_month=(month-1)*30;
"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has 31."
t_days=c_year+c _month+day;

cout<<"Days from"<<day<<"/"<<month<<"/"<<year<<" to January 1st. 2000:
"<<t_days;
}

Oct 10 '06 #4
Jim Langston wrote:
>
"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has 31."
Uh?!
Oct 10 '06 #5
Phlip wrote:
red floyd wrote:
>>void main()
>Undefined Behavior. Main *MUST* return int.

I suspect it's ill-formed syntax. That occurs before any behavior.
Whoops! You're right!
Oct 10 '06 #6

"Sumit Rajan" <su*********@gm ail.comwrote in message
news:4p******** ****@individual .net...
Jim Langston wrote:
>>
"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has
31."

Uh?!
er, 29. Yeah. That's what I meant to say :D

Oct 10 '06 #7
Jim Langston wrote:
"Sumit Rajan" <su*********@gm ail.comwrote in message
news:4p******** ****@individual .net...
>Jim Langston wrote:
>>"Thirty days has September, April, June and November, all the rest have
thirty one, except for February which has 28, except on leap years has
31."
Uh?!

er, 29. Yeah. That's what I meant to say :D
Easier one: "... all the rest have thirty one except for February which
is too complicated to discuss right now."
Oct 10 '06 #8
amackeyb wrote:
I need to do a program that calculate the days from a date whatever
since 20XX to January 1st. 2000. How can I do that??
I have this, is it correct???
No, it's not that simple.

Visit http://www.javascript.martin-steen.de/astrodate.html
and view the page source. Then you see the "AstroDate"
formula in JavaScript (should be easy to understand for
C-programmers ;)

Best regards, Martin

P.S. litte translation help for german/english:
Jahr = year
Monat = month
Tag = day

Oct 10 '06 #9

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

Similar topics

2
4748
by: JP SIngh | last post by:
Hi All I need to calculate the number of working days between the two dates entered on an ASP page. I am not that great a coder in ASP and was wondering if someone can help. Basically the form has Two textboxes to enter dates From Date - Fdate To Date - TDate
7
25996
by: Sam | last post by:
Hi, I use C# in my ASP.NET projects. Here's what I need to do: I want to add x business days to a given date i.e. add 12 business days to today's date. What is the best, fastest and most efficient way for me to do this? -- Thanks, Sam
9
2182
by: howzit | last post by:
I have a set date in my MySQL database that records when a Sales Lead is established and I echo that date as $row_rsLead; I need to be able to calculate how many days that lead has existed. $row_rsLead; outputs as 2007-06-14. I have made numerous attempts to create a function that will calculate the days between the lead_date and today's date, but have made absolutely no headway. I am either stuck working between differing date...
5
13671
by: Beemer Biker | last post by:
I cant seem to get that date into any DateTime to make my calculation directly by subtracting "01-01-0000" from "now". After reading this: http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11469&objectType=File I kluged up this routine that works: // convert date time into that funny matlab serial date time that starts at jan 1, 0000 private string DT2Matlab(DateTime thisDT)
7
5548
by: ngweixiong | last post by:
Hi, I have a Ms Access query which i used to calculate how many times the leadtime is a) less than 7 days b) 7-14 days c) more than 14 days With the query results, i will like to convert my results to percentage. E.G. how many percent is less than 7 days, 7-14 days and more than 14 days.
1
3348
by: ndindi22 | last post by:
Can someone plz help me. I'm working on leave application, have to calculate number of leave days available, starting from Startdate to Enddate of a contract. Where an employee get 1 day leave after 17 days from startdate of contract. How do I calculate the leave days, that accrue every after 17 days by 1. I'm using ASP and SQL Server 2000 (Query Analyzer) ndindi22
3
5963
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now calculate in the query the amount of weeks and days within the 17 days to show 2 weeks 3 days. I can create the function within excel, (A1 as cell with the days within it) as: =INT(A1/7) & " Weeks, " & MOD(A1,7) & " days" but cant seem to...
4
11208
by: shilpareddy2787 | last post by:
Hello, I have some total values, I want to calculate percenatge of these Total Values. I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period. How to calculate the Total Number of working Days in a given period . Let us say If i give the period as 08/01/2008 to 08/15/2008, I want total number of working days as 11. Please help me
15
6440
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but but that only gave me difference in hours and only if the times were on the same day (after wrapping with date() function). TIA
5
24556
FishVal
by: FishVal | last post by:
IMHO, the following is not a how-to-do instruction to solve a particular problem but more a concept-proof stuff demonstrating possibilities of SQL. So, let us say the problem is to calculate business days count which is defined as count of days (optionally inclusive in the current implementation) excluding weekend days and holidays. Let us say periods to calculate are stored in table associated with contacts. keyPeriodID -...
0
9641
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
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
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
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
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
6735
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2875
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.