Sponsored Content
Top Forums UNIX for Dummies Questions & Answers perl yesterday's date in mmddyyyy format Post 302333814 by rahulbahulekar on Tuesday 14th of July 2009 06:13:44 AM
Old 07-14-2009
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[4]+1,$T[3],($T[5]+1900)%100)'

But i want the date in mmddyyyy format; plz help.

Thankx,
Rahul Bahulekar.

---------- Post updated at 05:13 AM ---------- Previous update was at 05:07 AM ----------

got the answer -

perl -e '@T=localtime(time-86400);printf("%02d%02d%02d",$T[4]+1,$T[3],($T[5]+1900))'

just remove %100

thankx!!!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Date format in Perl

How do I display the date in the format "YYYY-Mmm-DD" using perl. e.g 2008-Jun-03 I have a perl command below which displays the date in the format "YYYY-MM-DD" but I want the month to be displayed as "Mmm" (The first 3 characters of the name of the month with the initial letter being upper... (2 Replies)
Discussion started by: stevefox
2 Replies

4. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

5. 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

6. Shell Programming and Scripting

Change the date format from mmddyyyy to yyyymmdd

How do I change the date format from mmddyyyy to yyyymmdd in PERL. Can any one help me please. (3 Replies)
Discussion started by: thankful123
3 Replies

7. Shell Programming and Scripting

Date conversion from DD MON YY to mmddyyyy

I am new shell scripting. Can someone please help in giving a shell script to convert from DD MON YY to mmddyyyy Example: Input1 :- 20 Apr 2011 Output2 should be :- 04202011 Input2 :- 09 MAR 11 Output :- 03092011 Input3 :- 30_JAN_11 Output :- 01302011 Need help in writing shell... (1 Reply)
Discussion started by: aakishore
1 Replies

8. Shell Programming and Scripting

How to Find number of days in a month in mmddyyyy format?

Hi Guru's, I am working on a shell script from past a month and unable to get rid of automating while working with dates,here's what i have. inital_date=11012011 final_date=11302011 expected_output= has to be in below format PFB 11012011 11022011 11032011 * * * 11102011 * *... (9 Replies)
Discussion started by: Gaurav198
9 Replies

9. Shell Programming and Scripting

Appending 0 to dates in mddyyyy format to make it mmddyyyy

There's a file whose date format for the year 2012 are currently in mddyyyy format that we are trying to change to mmddyyyy. Presuming that the grep command in the excerpt below is accurate, it looks like there are over forty-nine thousand records affected by the single-digit month format: -... (2 Replies)
Discussion started by: HLee1981
2 Replies

10. Shell Programming and Scripting

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: YEST=`perl -w... (3 Replies)
Discussion started by: thibodc
3 Replies
DateTime::Format::Natural(3pm)				User Contributed Perl Documentation			    DateTime::Format::Natural(3pm)

NAME
DateTime::Format::Natural - Create machine readable date/time with natural parsing logic SYNOPSIS
use DateTime::Format::Natural; $parser = DateTime::Format::Natural->new; $date_string = $parser->extract_datetime($extract_string); @date_strings = $parser->extract_datetime($extract_string); $dt = $parser->parse_datetime($date_string); @dt = $parser->parse_datetime_duration($date_string); if ($parser->success) { # operate on $dt/@dt, for example: printf("%02d.%02d.%4d %02d:%02d:%02d ", $dt->day, $dt->month, $dt->year, $dt->hour, $dt->min, $dt->sec); } else { warn $parser->error; } @traces = $parser->trace; DESCRIPTION
"DateTime::Format::Natural" takes a string with a human readable date/time and creates a machine readable one by applying natural parsing logic. CONSTRUCTOR
new Creates a new "DateTime::Format::Natural" object. Arguments to "new()" are options and not necessarily required. $parser = DateTime::Format::Natural->new( datetime => DateTime->new(...), lang => 'en', format => 'mm/dd/yy', prefer_future => '[0|1]', time_zone => 'floating', daytime => { morning => 06, afternoon => 13, evening => 20, }, ); o "datetime" Overrides the present now with a DateTime object provided. o "lang" Contains the language selected, currently limited to "en" (english). Defaults to '"en"'. o "format" Specifies the format of numeric dates, defaults to '"d/m/y"'. o "prefer_future" Turns ambiguous weekdays/months to their future relatives. Accepts a boolean, defaults to false. o "time_zone" The time zone to use when parsing and for output. Accepts any time zone recognized by DateTime. Defaults to 'floating'. o "daytime" An anonymous hash reference consisting of customized daytime hours, which may be selectively changed. METHODS
parse_datetime Returns a DateTime object constructed from a human readable date/time string. $dt = $parser->parse_datetime($date_string); $dt = $parser->parse_datetime(string => $date_string); o "string" The date string. parse_datetime_duration Returns one or two DateTime objects constructed from a human readable date/time string which may contain timespans/durations. Same interface and options as "parse_datetime()", but should be explicitly called in list context. @dt = $parser->parse_datetime_duration($date_string); @dt = $parser->parse_datetime_duration(string => $date_string); extract_datetime Returns parsable date/time substrings (also known as expressions) extracted from the string provided; in scalar context only the first parsable substring is returned, whereas in list context all parsable substrings are returned. Each extracted substring can then be passed to the "parse_datetime()"/ "parse_datetime_duration()" methods. $date_string = $parser->extract_datetime($extract_string); @date_strings = $parser->extract_datetime($extract_string); # or $date_string = $parser->extract_datetime(string => $extract_string); @date_strings = $parser->extract_datetime(string => $extract_string); success Returns a boolean indicating success or failure for parsing the date/time string given. error Returns the error message if the parsing did not succeed. trace Returns one or two strings with the grammar keyword for the valid expression parsed, traces of methods which were called within the Calc class and a summary how often certain units have been modified. More than one string is commonly returned for durations. Useful as a debugging aid. GRAMMAR
The grammar handling has been rewritten to be easily extendable and hence everybody is encouraged to propose sensible new additions and/or changes. See the classes "DateTime::Format::Natural::Lang::[language_code]" if you're intending to hack a bit on the grammar guts. EXAMPLES
See the classes "DateTime::Format::Natural::Lang::[language_code]" for an overview of currently valid input. BUGS &; CAVEATS "parse_datetime()"/"parse_datetime_duration()" always return one or two DateTime objects regardless whether the parse was successful or not. In case no valid expression was found or a failure occurred, an unaltered DateTime object with its initial values (most often the "current" now) is likely to be returned. It is therefore recommended to use "success()" to assert that the parse did succeed (at least, for common uses), otherwise the absence of a parse failure cannot be guaranteed. "parse_datetime()" is not capable of handling durations. CREDITS
Thanks to Tatsuhiko Miyagawa for the initial inspiration. See Miyagawa's journal entry <http://use.perl.org/~miyagawa/journal/31378> for more information. Furthermore, thanks to (in order of appearance) who have contributed valuable suggestions and patches: Clayton L. Scott Dave Rolsky CPAN Author 'SEKIMURA' mike (pulsation) Mark Stosberg Tuomas Jormola Cory Watson Urs Stotz Shawn M. Moore Andreas J. Koenig Chia-liang Kao Jonny Schulz Jesse Vincent Jason May Pat Kale Ankur Gupta Alex Bowley Elliot Shank Anirvan Chatterjee Michael Reddick Christian Brink Giovanni Pensa Andrew Sterling Hanenkamp Eric Wilhelm Kevin Field Wes Morgan Vladimir Marek Rod Taylor Tim Esselens Colm Dougan Chifung Fan Xiao Yafeng Roman Filippov SEE ALSO
dateparse, DateTime, Date::Calc, <http://datetime.perl.org> AUTHOR
Steven Schubiger <schubiger@cpan.org> LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. See <http://dev.perl.org/licenses/> perl v5.14.2 2012-05-31 DateTime::Format::Natural(3pm)
All times are GMT -4. The time now is 11:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy