473,406 Members | 2,894 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,406 software developers and data experts.

Time Calculation problem

rajiv07
141 100+
I have a script to calculate the warranty the period of one year.I add 365 days of current date.I got the correct output for the year 2007 but the 2008 year calculation getting incorrect value.please anybody explain me what is happening here.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Time::Local;
  3.  
  4. my $time=timelocal(0,0,0,21,4,2007);
  5.  
  6. my $warrenty="";
  7.  
  8. $warrenty=localtime($time+60*60*24*365);
  9.  
  10. print $warrenty;
  11.  
  12. print "\n";
  13.  
  14. $warrenty=localtime(time()+60*60*24*365);
  15.  
  16. print $warrenty;
  17.  
The output
--------------
Tue May 20 00:00:00 2008

Thu May 21 12:29:46 2009

Regards

Rajiv
May 21 '08 #1
4 1901
gpraghuram
1,275 Expert 1GB
I have a script to calculate the warranty the period of one year.I add 365 days of current date.I got the correct output for the year 2007 but the 2008 year calculation getting incorrect value.please anybody explain me what is happening here.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Time::Local;
  3.  
  4. my $time=timelocal(0,0,0,21,4,2007);
  5.  
  6. my $warrenty="";
  7.  
  8. $warrenty=localtime($time+60*60*24*365);
  9.  
  10. print $warrenty;
  11.  
  12. print "\n";
  13.  
  14. $warrenty=localtime(time()+60*60*24*365);
  15.  
  16. print $warrenty;
  17.  
The output
--------------
Tue May 20 00:00:00 2008

Thu May 21 12:29:46 2009

Regards

Rajiv
To get a future date or a previous date you can use this idea.
Use Tick count and add or subtract the number of days.

Expand|Select|Wrap|Line Numbers
  1. my @temp_var = split(/ /,localtime(time() - ($day_sub*86400)));
Here $day_sub is the number of days and here i am subtracting .
To get a later date use + instead of -

Raghuram
May 22 '08 #2
rajiv07
141 100+
To get a future date or a previous date you can use this idea.
Use Tick count and add or subtract the number of days.

Expand|Select|Wrap|Line Numbers
  1. my @temp_var = split(/ /,localtime(time() - ($day_sub*86400)));
Here $day_sub is the number of days and here i am subtracting .
To get a later date use + instead of -

Raghuram

Thanks Raghuram,

Actually my doubt is if i add 365 days in 22-05-2007 the output comes like 21-05-2008.But if i add the same 365 days in 22-05-2008 the output comes like
22-05-2009,But my expected output is 21-05-2009.
May 22 '08 #3
nithinpes
410 Expert 256MB
Thanks Raghuram,

Actually my doubt is if i add 365 days in 22-05-2007 the output comes like 21-05-2008.But if i add the same 365 days in 22-05-2008 the output comes like
22-05-2009,But my expected output is 21-05-2009.
That is because year 2008 is a leap year! The output is the expected one.
May 22 '08 #4
rajiv07
141 100+
That is because year 2008 is a leap year! The output is the expected one.
Thank nithinpes

But If i apply for this script for 01-21-2009 this gives 01-21-2010.but after 2007 the 2011 and 2015.. are gives my expected output.The years 2008,2009,2010 are not giving the expected output.

Regards
Rajiv
May 22 '08 #5

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

Similar topics

8
by: Aspersion | last post by:
I'm building an ASP page that has a lot of text and graphics. There is a calculation facility on the page. The user enters several numbers in a form and presses a button to see the calculated...
2
by: Terry | last post by:
I have used the code provided in the PreciseDateDiff function at the following Access Web link to calculate the time change date (from Daylight to Standard time and vice versa): ...
5
by: Tom | last post by:
A field in a data set I want to import into Access is in Unix time (seconds from a certain time on a certain date). Does anyone know the precise date and the precise time on that date that Unix is...
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
10
by: Drum2001 | last post by:
I have designed a "Time Tracker Database"... Basically a Time Clock. I have report that calculates the number of regular hours worked per week. Currently I am running the following query: ...
9
by: falcon | last post by:
Is there a way I can do time series calculation, such as a moving average in list comprehension syntax? I'm new to python but it looks like list comprehension's 'head' can only work at a value at...
8
by: andreas | last post by:
Hi, I have a calculation program in vb.net who is running for let us say for more than a hour. When I will do meanwhile something els in a office program I see that my calculation program takes a...
1
by: juliacjy | last post by:
Dear all, I'm needing an urgent help. I'm now maintaining a system which has a function of "Automatic Calculation". User is allowed to set of a time which then will be stored in one of my sql...
6
by: Lara1 | last post by:
I'm trying to get certain cells to show a hovering alert message when I click on them. (I don't want an error-message style box to pop up, because I'll eventually want it to show for lots of cells...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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,...
0
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...
0
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...
0
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...

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.