472,958 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1888
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.