Sponsored Content
Full Discussion: How to compare the dates..
Top Forums Shell Programming and Scripting How to compare the dates.. Post 302249924 by joeyg on Wednesday 22nd of October 2008 11:02:32 AM
Old 10-22-2008
Hammer & Screwdriver Maybe a different way to approach this task

I can determine 'seconds since Epoch' on a file modification
Code:
> touch file286
> stat -c%Y file286
1224687447

Touch'ed another file a little later - note greater number
Code:
> touch file287
> stat -c%Y file287
1224687482

Now I can see that 35 seconds actually elpased
Code:
> echo `stat -c%Y file287` - `stat -c%Y file286` | bc
35

So, by extension, you could touch a temp file (like my file287) and then compare the number of seconds difference. Just do the math to figure out how many seconds in your desired elapsed time period.

Last edited by joeyg; 10-22-2008 at 12:03 PM.. Reason: corrected spelling
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

compare two dates

I have a log file with date format like 10-Oct-02 13:20:29 ..... at the beginning of each line in the log file, and I need to grep data from this file to list the lines with date no longer than one days. I tried to use awk to do this but it looks very complicated to do it. Is there... (6 Replies)
Discussion started by: wchen
6 Replies

2. Programming

How to compare two dates

Hi I am writing a unix program. In that, i should compare two dates. I would like to know how to compare two dates in unix-whether they are same or not. pls help (5 Replies)
Discussion started by: bankpro
5 Replies

3. Programming

How to compare dates in C/C++

Hi, Is there any system defined function to compare two dates in C/C++? Thanks (1 Reply)
Discussion started by: naan
1 Replies

4. Shell Programming and Scripting

compare dates

Hi Gurus I am getting the timestamp of the last generated log file its like this "Oct 31 10:26" I want to compare this timestamp with the current date in shell script. I want to compare if the (timestamp-currentime) > 10 minutes how do i do this. Thanks Ragha (2 Replies)
Discussion started by: ragha81
2 Replies

5. Shell Programming and Scripting

compare dates...

hi all :) how can in compare yyyy/dd/mm with yyyy/dd/mm in perl i want the result like grater than or less than the given date... thanks in advance (3 Replies)
Discussion started by: i_priyank
3 Replies

6. Shell Programming and Scripting

Compare dates

Need to find all records where date in one filed is greater than date in other. Input: ABC 2 Filed3 CDG * X 20080903 20081031 180.00 ABD 2 Filed3 CDG * X 20081101 20081031 190.00 ABE 2 Filed3 CDG * X 20090903 20081031 120.00 ABC 2 Filed3 CDG * X 20080903 20081015 130.00 Output: ... (2 Replies)
Discussion started by: necroman08
2 Replies

7. Shell Programming and Scripting

compare dates

I want to compare a list of dates in a file with today's date & list only dates that are less than only 60 days old . please help . the date in the file are in format 11-FEB-2009 02-FEB-2009 26-JAN-2009 24-JAN-2009 13-JAN-2009 16-DEC-2008 10-DEC-2008 01-DEC-2008 25-NOV-2008 19-NOV-2008... (3 Replies)
Discussion started by: skamal4u
3 Replies

8. Shell Programming and Scripting

The Best Way to Compare Dates

Hi to all. When you have to compare a lot of dates in a SH code, there is a way to directly compare? For example, how can I check if two dates differ in less than a week? Thank's for reading. (2 Replies)
Discussion started by: daniel.gbaena
2 Replies

9. HP-UX

Compare dates

Hi, I want to convert two datetime fields to find out if the difference is one hour, in linux I've done this by converting both the datetime values to unix epoch time and subtracting them to find out if the difference is more than 3600s, however this does not work in hp-ux. I've these... (3 Replies)
Discussion started by: Random_Net
3 Replies

10. Shell Programming and Scripting

Compare Dates.

Hi All, I am entering StartDate and EndDate as parameters to script. Want to have an check saying, "If StartDate is greater than EndDate then don't execute the script". Pseudo Code: if then Execute script else exit 0 fi Can you please help me on the same? Thanks and... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies
STRTOTIME(3)								 1							      STRTOTIME(3)

strtotime - Parse about any English textual datetime description into a Unix timestamp

SYNOPSIS
int strtotime (string $time, [int $now = time()]) DESCRIPTION
The function expects to be given a string containing an English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in $now, or the current time if $now is not supplied. Each parameter of this function uses the default time zone unless a time zone is specified in that parameter. Be careful not to use dif- ferent time zones in each parameter unless that is intended. See date_default_timezone_get(3) on the various ways to define the default time zone. PARAMETERS
o $time -A date/time string. Valid formats are explained in Date and Time Formats. o $now - The timestamp which is used as a base for the calculation of relative dates. RETURN VALUES
Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure. ERRORS
/EXCEPTIONS Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the $TZ environment variable. See also date_default_timezone_set(3) CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | Prior to PHP 5.3.0, relative time formats sup- | | | plied to the $time argument of strtotime(3) such | | | as this week, previous week, last week, and next | | | week were interpreted to mean a 7 day period rel- | | | ative to the current date/time, rather than a | | | week period of Monday through Sunday. | | | | | 5.3.0 | | | | | | | Prior to PHP 5.3.0, 24:00 was not a valid format | | | and strtotime(3) returned FALSE. | | | | | 5.2.7 | | | | | | | In PHP 5 prior to 5.2.7, requesting a given | | | occurrence of a given weekday in a month where | | | that weekday was the first day of the month would | | | incorrectly add one week to the returned time- | | | stamp. This has been corrected in 5.2.7 and later | | | versions. | | | | | 5.1.0 | | | | | | | Now returns FALSE on failure, instead of -1. | | | | | 5.1.0 | | | | | | | Now issues the E_STRICT and E_NOTICE time zone | | | errors. | | | | | 5.0.2 | | | | | | | In PHP 5 up to 5.0.2, "now" and other relative | | | times are wrongly computed from today's midnight. | | | This differs from other versions where it is cor- | | | rectly computed from current time. | | | | | 5.0.0 | | | | | | | Microseconds began to be allowed, but they are | | | ignored. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A strtotime(3) example <?php echo strtotime("now"), " "; echo strtotime("10 September 2000"), " "; echo strtotime("+1 day"), " "; echo strtotime("+1 week"), " "; echo strtotime("+1 week 2 days 4 hours 2 seconds"), " "; echo strtotime("next Thursday"), " "; echo strtotime("last Monday"), " "; ?> Example #2 Checking for failure <?php $str = 'Not Good'; // previous to PHP 5.1.0 you would compare with -1, instead of false if (($timestamp = strtotime($str)) === false) { echo "The string ($str) is bogus"; } else { echo "$str == " . date('l dS of F Y h:i:s A', $timestamp); } ?> NOTES
Note If the number of the year is specified in a two digit format, the values between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999. See the notes below for possible differences on 32bit systems (possible dates might end on 2038-01-19 03:14:07). Note The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Prior to PHP 5.1.0, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. For 64-bit versions of PHP, the valid range of a timestamp is effectively infinite, as 64 bits can represent approximately 293 bil- lion years in either direction. Note Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash ( /), then the American m/d/y is assumed; whereas if the separator is a dash ( -) or a dot ( .), then the European d-m-y format is assumed. To avoid potential ambiguity, it's best to use ISO 8601 ( YYYY-MM-DD) dates or DateTime::createFromFormat when possible. Note Using this function for mathematical operations is not advisable. It is better to use DateTime::add and DateTime::sub in PHP 5.3 and later, or DateTime::modify in PHP 5.2. SEE ALSO
Date and Time Formats, DateTime::createFromFormat, checkdate(3), strptime(3). PHP Documentation Group STRTOTIME(3)
All times are GMT -4. The time now is 05:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy