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
6 5150
You'll have to calculate it. Look into this module for date manipulation routines: cpan Date::Calc
- Miller
Thanks for your reply. I will look into the document that you mentioned.
Thanks,
Sangith
if you can get the date/time in seconds from the epoch calculating yesterdays date is very easy:
$yesterday = time - 86400;
print scalar $yesterday;
You can even use localtime as below with some simple manipulations as below. - $yesterday_date=get_yesterday();
-
print "$yesterday_date";
-
-
sub get_yesterday
-
{
-
my ($csec,$cmin,$chr,$cmday,$cmon,$cyear,$cwday,$cyday) = localtime(time) ;
-
-
$cmday-=1;
-
if(length($cmday) == 1) { $cmday = '0' . $cmday }
-
-
$cmon+=1;
-
if(length($cmon) == 1) { $cmon = '0' . $cmon }
-
-
$cyear+=1900;
-
-
my $cDate = "$cmday/$cmon/$cyear";
-
-
return $cDate;
-
}
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
alcazar,
the better way is to subtract a days worth of seconds from time: - 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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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.
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: 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,...
|
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...
|
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...
| |