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

Module for calculating previous day's date

25
Hi,

Is there any module which checks for the previous day's date. For eg I run the program which gives me the current date and I have to check another log file to see if it contains the timestamp as the previous day's date. If it is present, I have to print that particular line to the screen.

So please let me know if there is a module available to check for the previous day date.

Thanks,
Sangith
Jun 19 '07 #1
6 5150
miller
1,089 Expert 1GB
You'll have to calculate it. Look into this module for date manipulation routines:

cpan Date::Calc

- Miller
Jun 19 '07 #2
sangith
25
Thanks for your reply. I will look into the document that you mentioned.

Thanks,
Sangith
Jun 19 '07 #3
KevinADC
4,059 Expert 2GB
if you can get the date/time in seconds from the epoch calculating yesterdays date is very easy:

$yesterday = time - 86400;
print scalar $yesterday;
Jun 19 '07 #4
alcazar
10
You can even use localtime as below with some simple manipulations as below.

Expand|Select|Wrap|Line Numbers
  1. $yesterday_date=get_yesterday();
  2. print "$yesterday_date";
  3.  
  4. sub get_yesterday
  5. {
  6. my ($csec,$cmin,$chr,$cmday,$cmon,$cyear,$cwday,$cyday) = localtime(time) ;
  7.  
  8.   $cmday-=1;
  9.   if(length($cmday) == 1) { $cmday = '0' . $cmday }
  10.  
  11.   $cmon+=1;
  12.   if(length($cmon) == 1) { $cmon = '0' . $cmon }
  13.  
  14.   $cyear+=1900;
  15.  
  16.   my $cDate = "$cmday/$cmon/$cyear";
  17.  
  18. return $cDate;
  19. }
NOTE:localtime function would return the time which is set on the local macine/web server on which the perl script is executed.

cheers,
Alcazar


Thanks for your reply. I will look into the document that you mentioned.

Thanks,
Sangith
Jun 20 '07 #5
KevinADC
4,059 Expert 2GB
alcazar,

the better way is to subtract a days worth of seconds from time:

Expand|Select|Wrap|Line Numbers
  1. my ($csec,$cmin,$chr,$cmday,$cmon,$cyear,$cwday,$cyday) = localtime(time-86400) ;
now you accurately have yesterdays date.

Your suggested way will not always work properly. For example, if the day of the month is 1 (one), you will end up with zero after subtracting one day. There is no such day in a month as zero. Also, the month will not roll back properly either.

Kevin
Jun 20 '07 #6
miller
1,089 Expert 1GB
You can even use localtime as below with some simple manipulations as below.
Yes, as Kevin said, rolling your own data calculation routines is a waste of time. Either do calculations in time since epoch, or use the Date::Calc module to manipulate based individual date parts. There is no reason to do it otherwise, and plenty of reasons not to.

- Miller
Jun 20 '07 #7

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

Similar topics

12
by: Anthony Robinson | last post by:
Is anyone aware of a function (system or user defined) that will calculate business days? For instance: I have a column in as table called DATE. I want to be able to add five business days to that...
1
by: Shaun Thornburgh | last post by:
Hi, I have a table called Bookings which has two important columns; Booking_Start_Time and Booking_End_Time. These columns are both of type DATETIME. Given any day how can I calculate how many...
2
by: Gustavo G. Rondina | last post by:
It is possible to caclulate every year's easter using simple mathematical operations. Here is a code that does the trick: http://www.brlivre.org/c/easter.c I found the math scheme in an...
2
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous...
5
by: cbalian | last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition: I need the result that would return the date of the Thursday after the...
1
by: Del | last post by:
I have a parameter query that requires the user to enter a Start Date: and End Date: and pull data between that date range. I am currently using the following parameter; Select * From mytable...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
4
by: gimme_this_gimme_that | last post by:
Is there a way to get the last day of the previous business quarter from DB2? For 10/21/2008 the day would be 9/30/2008. Thanks.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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,...
0
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...
0
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...

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.