Sponsored Content
Full Discussion: date comparision
Operating Systems Solaris date comparision Post 302142442 by dave_nithis on Friday 26th of October 2007 07:35:29 AM
Old 10-26-2007
Data Compare two dates using shell scripting

a=2007-05-10 (YYYY-DD-MM Format)
b=2007-06-10

These are the two given dates and I need to compare.
(First It should split the dates into YYYY,dd,mm)

The script should first compare years(2007 here).If both are same or if "a" is lesser than "b"(ie.suppose year in "a" is 2006),it should print correct.If "a"(ie. suppose year in a is 2008) is greater than b,then it should print error.Similarly for the dates(05 and 06).

No need to check for the months(10).

Regards,
Dave Nithis.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

date comparision

Hello, I am trying to compare two dates which are in variables and i am not getting the correct result as expected. $first_date = '07/19/2007' $second_date='07/20/2007' Can you please suggest how to i check whether they are equal or not. if ($first_date -eq $second_date) condition is not... (3 Replies)
Discussion started by: kotasateesh
3 Replies

2. Shell Programming and Scripting

while - comparision

Hi, Please find the attached scriplet and suggest me to fix the bug in this. ----------------------------------- noofdirs=`ls *.tar | wc -l` if ; then let i=1 while ( $i <= $noofdirs ) ; do echo $i mkdir $i file1=`ls *.tar | head -1` mv $file1 $i i =... (2 Replies)
Discussion started by: sharif
2 Replies

3. Shell Programming and Scripting

Date Comparision in the File

Hi All, I have thefollowing files in the directory inbox/sat ras.sat.trn.20090103.001902.00004358 ras.sat.trn.20090612.001903.00005339 ras.sat.trn.20090723.001902.00004358 The above file contains the date of the file creation. We just need to write a ksh shell script to check the... (5 Replies)
Discussion started by: satheesh_color
5 Replies

4. Shell Programming and Scripting

Problem with Date Comparision

Hi, I have a file which has the date in the last line in the example pasted along with the rates of the countries. -- I want to compare the date in the last line of the file mentioned in the example below with the system date from Monday to Friday. -- If system date is equal to the date... (2 Replies)
Discussion started by: Raji_gadam
2 Replies

5. Shell Programming and Scripting

problem in date comparision

#!/bin/ksh var="2009-08-31 12:39:05 UTC" ddate=`echo $var|cut -d' ' -f1` y1=`echo $ddate|cut -d'-' -f1` m1=`echo $ddate|cut -d'-' -f2` d1=`echo $ddate|cut -d'-' -f3` filedate=$y1$m1$d1 currdate="20070814" if ]; then echo "$LINE -> $filedate LOWER THAN $currdate" ... (0 Replies)
Discussion started by: HemaV
0 Replies

6. Programming

Problem with date comparision in Pro*C

Hi, I have written the following Pro*C program to get the difference between 2 dates.But when I am printing the value of the date difference,it is always showing 0. #include<stdio.h> #include<sqlca.h> #include<oraca.h> void main() { EXEC SQL BEGIN DECLARE SECTION; int diff; ... (4 Replies)
Discussion started by: sureshbabuc
4 Replies

7. Shell Programming and Scripting

Date - String comparision

Hi, I am having difficulty to compare a string in a file against a date from a a table and print the latest date. Below are the values. String in File : 2009-12-02 00:37:51 Value Table : 2010-01-10-02.00.49.294758 I have to compare both the values ( Ignore the Microsecond in the table... (5 Replies)
Discussion started by: sam_78_nyc
5 Replies

8. Shell Programming and Scripting

Date Manipulation and Comparision

Hi All, I want to generate quarter dates using awk or anything, by giving a dates as input for example : start_date=2010-01-01 end_date=2010-05-31 output should be: start_date end_date qtr 2010-01-01 2010-03-31 1 2010-04-01 2010-05-31 2 Example 2:... (1 Reply)
Discussion started by: sol_nov
1 Replies

9. Shell Programming and Scripting

Date comparision in Unix

Hi All, I would need your help to compare dates in my script. Say if I have the dates in a file I need to comapre these dates with yesterday's date and the dates which are older than yesterday needs to be displayed. Example: 03/22/2012 03/24/2012 03/20/2012 03/21/2012 03/12/2012... (1 Reply)
Discussion started by: pdreddy34
1 Replies

10. Shell Programming and Scripting

Date command comparision with a different format

I have a script called " passwd_status " which gives the passwd-s status of my servers. the script output is like below password status for A: abc ks 10/05/115 1 30 ps password status for B: abc ks 09/25/115 1 30 ps password status for C: abc ks 10/10/115 1 30 ps Now , i want to... (1 Reply)
Discussion started by: charanarjun
1 Replies
DateTime::Format::Mail(3pm)				User Contributed Perl Documentation			       DateTime::Format::Mail(3pm)

NAME
DateTime::Format::Mail - Convert between DateTime and RFC2822/822 formats SYNOPSIS
use DateTime::Format::Mail; # From RFC2822 via class method: my $datetime = DateTime::Format::Mail->parse_datetime( "Sat, 29 Mar 2003 22:11:18 -0800" ); print $datetime->ymd('.'); # "2003.03.29" # or via an object my $pf = DateTime::Format::Mail->new(); print $pf->parse_datetime( "Fri, 23 Nov 2001 21:57:24 -0600" )->ymd; # "2001-11-23" # Back to RFC2822 date use DateTime; my $dt = DateTime->new( year => 1979, month => 7, day => 16, hour => 16, minute => 45, second => 20, time_zone => "Australia/Sydney" ); my $str = DateTime::Format::Mail->format_datetime( $dt ); print $str; # "Mon, 16 Jul 1979 16:45:20 +1000" # or via an object $str = $pf->format_datetime( $dt ); print $str; # "Mon, 16 Jul 1979 16:45:20 +1000" DESCRIPTION
RFCs 2822 and 822 specify date formats to be used by email. This module parses and emits such dates. RFC2822 (April 2001) introduces a slightly different format of date than that used by RFC822 (August 1982). The main correction is that the preferred format is more limited, and thus easier to parse programmatically. Despite the ease of generating and parsing perfectly valid RFC822 and RFC2822 people still get it wrong. So this module provides four things for those handling mail dates: 1 A strict parser that will only accept RFC2822 dates, so you can see where you're right. 2 A strict formatter, so you can generate the right stuff to begin with. 3 A loose parser, so you can take the misbegotten output from other programs and turn it into something useful. This includes various minor errors as well as some somewhat more bizarre mistakes. The file t/sample_dates in this module's distribution should give you an idea of what's valid, while t/invalid.t should do the same for what's not. Those regarded as invalid are just a bit too strange to allow. 4 Interoperation with the rest of the DateTime suite. These are a collection of modules to handle dates in a modern and accurate fashion. In particular, they make it trivial to parse, manipulate and then format dates. Shifting timezones is a doddle, and converting between formats is a cinch. As a future direction, I'm contemplating an even stricter parser that will only accept dates with no obsolete elements. CONSTRUCTORS
new Creates a new "DateTime::Format::Mail" instance. This is generally not required for simple operations. If you wish to use a different pars- ing style from the default, strict, parser then you'll need to create an object. my $parser = DateTime::Format::Mail->new() my $copy = $parser->new(); If called on an existing object then it clones the object. It has two optional named parameters. o "loose" should be a true value if you want a loose parser, else either don't specify it or give it a false value. o "year_cutoff" should be an integer greater than or equal to zero specifying the cutoff year. See "set_year_cutoff" for details. my $loose = DateTime::Format::Mail->new( loose => 1 ); my $post_2049 = DateTime::Format::Mail->new( year_cutoff => 60 ); clone For those who prefer to explicitly clone via a method called "clone()". If called as a class method it will die. my $clone = $original->clone(); PARSING METHODS
These methods work on either our objects or as class methods. loose, strict These methods set the parsing strictness. my $parser = DateTime::Format::Mail->new; $parser->loose; $parser->strict; # (the default) my $p = DateTime::Format::Mail->new->loose; parse_datetime Given an RFC2822 or 822 datetime string, return a "DateTime" object representing that date and time. Unparseable strings will cause the method to die. See the synopsis for examples. set_year_cutoff Two digit years are treated as valid in the loose translation and are translated up to a 19xx or 20xx figure. By default, following the specification of RFC2822, if the year is greater than '49', it's treated as being in the 20th century(19xx). If lower, or equal, then the 21st(20xx). That is, 50 becomes 1950 while 49 is 2049. "set_year_cutoff()" allows you to modify this behaviour by specifying a different cutoff. The return value is the object itself. $parser->set_year_cutoff( 60 ); year_cutoff Returns the current cutoff. Can be used as either a class or object method. my $cutoff = $parser->set_year_cutoff; default_cutoff Returns the default cutoff. A useful method to override for subclasses. my $default = $parser->default_cutoff; fix_year Takes a year and returns it normalized. my $fixed = $parser->fix_year( 3 ); FORMATTING METHODS
format_datetime Given a "DateTime" object, return it as an RFC2822 compliant string. use DateTime; use DateTime::Format::Mail; my $dt = DateTime->new( year => 1979, month => 7, day => 16, time_zone => 'UTC' ); my $mail = DateTime::Format::Mail->format_datetime( $dt ); print $mail, " "; # or via an object my $formatter = DateTime::Format::Mail->new(); my $rfcdate = $formatter->format_datetime( $dt ); print $rfcdate, " "; THANKS
Dave Rolsky (DROLSKY) for kickstarting the DateTime project. Roderick A. Anderson for noting where the documentation was incomplete in places. Joshua Hoblitt (JHOBLITT) for inspiring me to check what the standard said about interpreting two digit years. SUPPORT
Support for this module is provided via the datetime@perl.org email list. See <http://datetime.perl.org/mailing_list.html> for more details. Alternatively, log them via the CPAN RT system via the web or email: http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DateTime%3A%3AFormat%3A%3AMail bug-datetime-format-mail@rt.cpan.org This makes it much easier for me to track things and thus means your problem is less likely to be neglected. LICENCE AND COPYRIGHT
Copyright E<copy> Iain Truskett, 2003. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the licences can be found in the Artistic and COPYING files included with this module, or in perlartistic and perlgpl in Perl 5.8.1 or later. AUTHOR
Originally written by Iain Truskett <spoon@cpan.org>, who died on December 29, 2003. Maintained by Dave Rolsky <autarch@urth.org>. SEE ALSO
"datetime@perl.org" mailing list. <http://datetime.perl.org/> perl, DateTime RFCs 2822 and 822. perl v5.8.8 2007-09-11 DateTime::Format::Mail(3pm)
All times are GMT -4. The time now is 07:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy