Perl add one minute to the given date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Perl add one minute to the given date
# 1  
Old 07-19-2011
Perl add one minute to the given date

Hello Gurus,

We have a query where we need to add one minute ( also we need to add 12 hrs in another query) to given date.

we tried using some functionalities like 'perl -e @d= $run_dt + 600' . however we were not succeeded.

Basically issue is we get date in following format "May18 2011 9:50PM"

we need output as "May 18 2011 9:51PM" ( add one min)

if its additiona of 12 hrs. it should be something like "May 19 2011 9:50AM"

Thanking you in anticipation.
# 2  
Old 07-19-2011
Code:
perldoc Date::Manip

Code:
perl -Mstrict -MDate::Manip -e 'my $date="May18 2011 9:50PM";my $newDate=DateCalc($date, "10 Minutes"); print "$newDate\n";'

# 3  
Old 07-19-2011
Thanks Skrynesaver, Unfortunately perldoc Date::Manip is not a valid module / does not exist in the linux version i am using.

Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2.6.18-164.11.1.el5
is the verion i am using.

Thanks
# 4  
Old 07-19-2011
Then I guess it's FormatToEpoch=>Add delta=>EpochToFormat.
Code:
perldoc -f localtime

@components=localtime($epoch_time)

The DateTime module may resolve the FormatToEpoch issues.
# 5  
Old 07-19-2011
Yes.. But here i am stuck on how to convert "May 18 2011 9:50PM" into epoch seconds and viceversa... My given date contains AM/PM and no seconds ... Could you help me out ?
# 6  
Old 07-19-2011
You could install the Date::Manip and make your life easier
or you may try something like this:

Code:
perl '-MPOSIX qw(strftime)' -le'

  $dt = qx/date -d "$ARGV[0]" +%s/ + $ARGV[1] * 60 * 60;
  
  print strftime "%B %d %Y %H:%M%p", localtime $dt;
  
  ' 'May 18 2011 9:50AM' 24


Code:
zsh-4.3.11[sysadmin]% perl '-MPOSIX qw(strftime)' -le'

  $dt = qx/date -d "$ARGV[0]" +%s/ + $ARGV[1] * 60 * 60;

  print strftime "%B %d %Y %H:%M%p", localtime $dt;

  ' 'May 18 2011 9:50AM' 24
May 19 2011 09:50AM

P.S. The solution is not portable because it relies on the GNU date program.

Last edited by radoulov; 07-19-2011 at 11:49 AM..
# 7  
Old 07-19-2011
Its working fine from command prompt... Could you suggest me how to implement the same in perl(.pl) script.. I tried but not succeeded
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to add those that have the same minute in a file

Hi All, Need your help on how i can sum up the values. I have a file that contains the count and the time. I wanted to add up all the first column having the same datestamp. Please see below. INPUT 1721 2015-12-26 00:01 1440 2015-12-26 00:02 1477 2015-12-26 00:02 411 ... (4 Replies)
Discussion started by: ernesto
4 Replies

2. Shell Programming and Scripting

Comparing date and check minute difference

Dear all, I'm stuck on Solaris 9 bash (I believe is quite different from Linux system) trying to find a solution. I have one file named like:120629-1750-TERZ81_AS_YTR.txt YYMMDD-HH-MM-......The script should compare the actual date with the one reported on the file name and then take an action... (4 Replies)
Discussion started by: Lord Spectre
4 Replies

3. Shell Programming and Scripting

Take minute per minute from a log awk

Hi, I've been trying to develop a script that performs the parsing of a log every 1 minute and then generating some statistics. I'm fairly new to programming and this is why I come to ask if I can lend a hand. this is my log: xxxx 16/04/2012 17:00:52 - xxxx714 - E234 - Time= 119 ms.... (8 Replies)
Discussion started by: jockx
8 Replies

4. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

5. Shell Programming and Scripting

Count of matched pattern occurences by minute and date in a log file

Anyone knows how to use AWK to achieve the following Sun Feb 12 00:41:01-00:41:59 Success:2 Fail:2 Sun Feb 12 00:42:01-00:42:59 Success:1 Fail:2 Sun Feb 12 01:20:01-01:20:59 Success:1 Fail:2 Mon Feb 13 22:41:01-22:41:59 Success:1 Fail:1 log file: Success Success Fail Fail ... (9 Replies)
Discussion started by: timmywong
9 Replies

6. Shell Programming and Scripting

Extract week start,end date from given date in PERL

Hi All, what i want to do in perl is i should give the date at run time .Suppose date given is 23/12/2011(mm/dd/yyyy) the perl script shold find week start date, week end date, previous week start date,end date,next week start date, end date. In this case week start date will be-:12/19/2011... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

7. UNIX for Dummies Questions & Answers

How to add an hour or a minute to a time?

Hi, The timestamp is June 06 2011 11:05AM i need 2 results. first, an hour added to it, June 06 2011 12:05AM second, a minute added to it, June 06 2011 11:06AM How can i do this? Also when it reaches 12:59, it needs to start from 1 again without giving the output as 13:00. it... (17 Replies)
Discussion started by: irudayaraj
17 Replies

8. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies
Login or Register to Ask a Question