perl one-liner to get yesterday's date in format dd-MMM-yy (i.e. 01-JAN-12)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl one-liner to get yesterday's date in format dd-MMM-yy (i.e. 01-JAN-12)
# 1  
Old 07-15-2012
perl one-liner to get yesterday's date in format dd-MMM-yy (i.e. 01-JAN-12)

I have the following perl one-liner to get yesterday's date, but I would like it in the form of dd-MMM-yy (for example: 01-JAN-12). Can someone alter the below code so I get the format I want? Also, could someone also give me a line for dd-Mmm-yy (for example 01-Jan-12)?

Code:
Code:
YEST=`perl -w -e '@yest=localtime(time-86400);printf "%d%.2d%.2d",$yest[5]+1900,$yest[4]+1,$yest[3];'`


Last edited by radoulov; 07-16-2012 at 10:09 AM..
# 2  
Old 07-16-2012
Code:
perl -e 'use POSIX qw(strftime);$now_string = strftime "%e-%b-%Y", localtime(time-86400); print $now_string,"\n";'

This User Gave Thanks to pravin27 For This Post:
# 3  
Old 07-16-2012
Thanks so much...I'll give it a try today!
# 4  
Old 07-16-2012
Just nitpicking:
Code:
root# date -s '12 Mar 2012 00:10'
Mon Mar 12 00:10:00 EDT 2012
$ perl -MPOSIX -le'print strftime "%e-%b-%Y",localtime(time-86400)'
10-Mar-2012

$ perl -MPOSIX -le'@a=localtime;--$a[3];print strftime "%e-%b-%Y",@a'
11-Mar-2012


Last edited by binlib; 07-16-2012 at 11:58 AM.. Reason: Added fix
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Date format from Jan 01 2015 11:00:00 PM to 01/01/2015 23.00.00

I need to change Date and time stamp format from Jan 01 2015 11:00:00 PM to 01/01/2015 23.00.00 Existing Format : Mon DD YYYY hh:mi:ss AM/PM (Jan 01 2015 11:00:00 PM) Expected Format: MM/DD/YYYY hh.mi.ss 24 hours (01/01/2015 23.00.00) I need to update enitire file where... (3 Replies)
Discussion started by: esivaprasad
3 Replies

2. Shell Programming and Scripting

How do i compare two dates with format Jan 01, 2012 and Jan 00 2012

I need to be able to compare dates in the format of Jan 10, 2012 and Jan 10 2012. (Notice one has a comma). Then I need to find the date that is 7 days before those dates if they are equal. How can I do this in Bash. Thank ahead (4 Replies)
Discussion started by: ojthejuice
4 Replies

3. Shell Programming and Scripting

Perl one-liner convert to script format problem asking

Input_file_1: ABC1 DEF11 ABC3 DEF7 ABC7 DEF36 Input_file_2: DEF7 light 23 DEF11 over 2 DEF11 over 1 DEF17 blue 0 Perl one-liner that join two input file based on columns sharing a value (In this example, column 2 in Input_file_1 and column 1 in... (3 Replies)
Discussion started by: perl_beginner
3 Replies

4. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

5. UNIX for Dummies Questions & Answers

perl yesterday's date in mmddyyyy format

Hi, Below command is producing yesaterday's date in mmddyy format - perl -e '@T=localtime(time-86400);printf("%02d%02d%02d",$T+1,$T,($T+1900)%100)' But i want the date in mmddyyyy format; plz help. Thankx, Rahul Bahulekar. ---------- Post updated at 05:13 AM ---------- Previous... (1 Reply)
Discussion started by: rahulbahulekar
1 Replies

6. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies

7. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

8. Shell Programming and Scripting

ddmmyyyy to dd-mmm-yy format?

Hi All, Can anyone tell me a simple way of converting a date in ddmmyyyy format to dd-mmm-yy format. For example 17022006 to 17-FEB-06 Thanks in advance Regards, Gaurav (11 Replies)
Discussion started by: gauravgoel
11 Replies

9. HP-UX

How can i get the yesterday's date in YYYYMMDD format

How can i get the yesterday's date in YYYYMMDD format??? (4 Replies)
Discussion started by: prasadsr
4 Replies

10. UNIX for Dummies Questions & Answers

get yesterday date in yyyymmdd format

I would like to know how I could get a yesterday date in yyyymmdd e.g. today is 20011109, and I would like to get 20011108. Thank you!:confused: (2 Replies)
Discussion started by: hk_newbie
2 Replies
Login or Register to Ask a Question