Sponsored Content
Top Forums Shell Programming and Scripting Get date and time for past 1 hour from current date Post 302152696 by Perderabo on Thursday 20th of December 2007 11:13:18 PM
Old 12-21-2007
One way:
$ perl -e '@d=localtime time()-3600; printf "%4d%02d%02d%02d%02d%02d\n", $d[5]+1900,$d[4]+1,$d[3],$d[2],$d[1],$d[0]'
20071220220154
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

param as current date+time

Hi All, I need to pass param on aix "errpt -a -s MMDDHHMMYY -e MMDDHHMMYY". How do I read the date+time on the system and pass it as parameter? I need also the -s as previous day and the -e as current day. Thanks, itik (1 Reply)
Discussion started by: itik
1 Replies

2. Shell Programming and Scripting

How to find a date which is 7 days past when given current date

hii all. I have to get the date of the 7th day past from the current date. if i give the current date as sep 3 then i must get the date as 27th of august. can we get the values from the "cal" command. cal | awk '{print $2}' will this type of command work. actually my need is if today is... (17 Replies)
Discussion started by: ladtony
17 Replies

3. Shell Programming and Scripting

Compare file timestamp with current date. Diff must be 1 hour.

Hello, I've created the script below to compare the content of two files with a delay of an hour. After an hour, the lines that exist in both files, will be printed and executed. The script now uses a counter to countdown 50 minutes. But what I would prefer is to check the file timestamp of... (3 Replies)
Discussion started by: taipan
3 Replies

4. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

5. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

6. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

7. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

8. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

9. Shell Programming and Scripting

Seven days past date from current date

hi all.. i want 2 know how 2 find 7days past date from current date.. when i used set datetime = `date '+%m%d%y'` i got 060613.. i just want to know hw to get 053013.. i tried using date functions but couldnt get it :( i use c shell and there is no chance that i can change that ..... (3 Replies)
Discussion started by: Rahul619
3 Replies

10. Shell Programming and Scripting

Need to substract date with current date and time

I have below file which contain the date in column 3,4,5 12345 open 10/10/13 10:08 PM 3 application is in java 67899 open 12/10/13 2:31 AM 2 apps can be reach 23456 open 11/9/13 2:31 AM 4 java is OK 65432 open 12/10/13 10:07 PM 9 we are... (1 Reply)
Discussion started by: vijay_rajni
1 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 12:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy