LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-12-2009, 05:01 AM   #1
miran_shahverdyan
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
date command


I need to compare 2 dates in european format (dd/mm/yyy).
date -d<my date> %s command converts date into unix epoch (integer), thus make it easy to compare.

The problem is that -d (or --date) option interprets date in US format-ie mm/dd/yyy.
Thanks in advance!
 
Old 10-12-2009, 05:15 AM   #2
ComradeP
LQ Newbie
 
Registered: Oct 2009
Posts: 12

Rep: Reputation: 2
If you use slashes (i.e. 07/08/09), this is interpreted as the US format:

Code:
% date -d07/08/09 +%d-%B-%y
08-July-09
You might try to use dashes instead:

Code:
% date -d07-08-09 +%d-%B-%y
09-August-07
Note that this forces the interpretation of yy-mm-dd. I'm not aware of a way to make date parse strings as dd/mm/yy.

Having said that, it would be easy to translate your European strings into the American format for date. For example:

Code:
% function eudate() {
    date -d `echo $1 | perl -p -i -e 's|(\d\d)/(\d\d)/(\d\d)|$2/$1/$3|g'` +%d-%B-%y
}
% eudate 07/08/09
07-August-09

Last edited by ComradeP; 10-12-2009 at 05:19 AM.
 
Old 10-12-2009, 12:29 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Warning: Off-Topic....

ComradeP,

Yours is only the second post I have seen here where the OP has, in his first post, answered rather than asked a question.
[The only other was here]

So, I'm just saying "Thanks for your advice and Welcome Aboard"
 
Old 10-12-2009, 01:15 PM   #4
ComradeP
LQ Newbie
 
Registered: Oct 2009
Posts: 12

Rep: Reputation: 2
Hah, being bored at work does that to you. Thanks for the welcome, though.
 
Old 10-14-2009, 06:59 AM   #5
miran_shahverdyan
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Original Poster
Rep: Reputation: 0
THX

Hi,

Actually it is discovered that its not possible to use european dates in date command (strange..).

So I wrote my own script doing that...
Thanks for all ideas anyways!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
date command problems titopoquito Linux - Software 1 08-06-2009 04:55 AM
date command is not accepting monu Linux - General 7 10-25-2007 09:20 AM
command for date DarReNz Solaris / OpenSolaris 7 09-05-2006 09:53 AM
date command aetucker1 Linux - General 3 01-21-2005 12:57 PM
date command and the use of %Z tag hq4ever Linux - Newbie 2 09-04-2004 12:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration