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

write a program which can calculate the date after 1 year when some date is entered.

the program should accept the current date, month and year and should calculate 1 year later date.
Jan 27 '10 #1
5 4289
johny10151981
1,059 1GB
do the math first. you may reach some where
Jan 27 '10 #2
donbock
2,426 Expert 2GB
What do you mean by "1 year later date"? The trivial answer is to keep the day and month unchanged and simply increment the year. Do you need to do something more complicated, such as:
  • Report what the date will be 365 days in the future;
  • Report what the day of the week is on both the entered date and the future date.

These more complicated problem statements are affected by whether or not there is an intervening leap year; the trivial approach is not affected by leap year.
Jan 27 '10 #3
Just check with year for leap year.

If(Year %4 == 0)
{
if ( Month <=2)
{
Year++;
DateCalc(Day, Month, Year);
}
}
else if(Year+1%4 == 0)
{
if (Month > 2)
{
Year++;
DateCalc(Day, Month, Year)
}
}
else
{
Year++;
}


DateCalc(day, month, year)
{

if( day !=1 )
{
day-1, month, year;
}
else
{
if (month ==5 or 7 or 8 or 10 or 12)
{
day = 31; month--; year;
}
else if (month 2 or 4 or 6 or 9 or 11)
{
day = 30; month--; year;
}
else if (month == 3 && year%4==0)
{
day = 29; month--; year;
}
else if (month ==3 && year%4 != 0)
{
day = 28; month--; year;
}
else //if(month==1)
{
day = 31; month = 12; year--;
}

}



Funny Answer Isn't it,
Its my first one on this site.
Jan 27 '10 #4
weaknessforcats
9,208 Expert Mod 8TB
This code does not correctly check for a leap year nor does the DateClac function work.

Avoid posting code solutions. Instead, post a description of what needs to be done.
Jan 27 '10 #5
donbock
2,426 Expert 2GB
@donbock
Not quite true! If today is Feb 29, then one year from now is Mar 1. Leap year is always a factor.

There are a surprising number of corner cases in date calculations. That's why it is so important to fully and carefully specify the desired behavior. You can achieve a pretty good specification with explanatory text and a few carefully chosen examples.

A very useful assumption is to take the calendar in use today and project it forward and backward in time. That is, ignore the transition from Julian to Gregorian calendar that occurred at different times with differing impact in different countries.
Jan 27 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tencip | last post by:
Hi everyone, I'm trying to build a simple script that does the following. It should find today's month and year, and then go into a DB query string and look for all records that are from this...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are often posted by incomers here. That sort of code...
4
by: Jan Szymczuk | last post by:
I'm creating an MS Access 2000 database where I have a number of people entered using simple basic fields, Surname: SMITH Forenames: John DoB: 09/09/1958 Age:...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
26
by: jshanman | last post by:
I am writing a timeline that uses Google Maps. I have a function that converts a date time to latitude coords. This function is used to draw the markers on the timeline. I need a reverse function...
7
by: Gucci | last post by:
<?php /** * check ine year is a leap year, and return the month day array * * @param int $year **the year must bigger than zero** * @return array */ function is_leap_year($year){...
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
2
by: jocobunshin | last post by:
Hi there! I'm new in Turbo C... uhmm our teacher gave us a project to make a program in Turbo C. Im from the Philippines, and our project is due on tuesday, februrary 13, 2007... can anyone check my...
2
by: AccessHunter | last post by:
Hi, I have a table (Admittance) that has birth dates of all cases admitted, fields being (Case Number and Birth Date). I also have a form that asks the user to select a year and click the 'Find'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.