LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-22-2004, 08:49 PM   #1
lifetaster
LQ Newbie
 
Registered: Feb 2004
Location: Singapore
Distribution: HP-UX
Posts: 29

Rep: Reputation: 15
date command question


date=`date -u +%m/%d/%Y`
echo "$date"

with the commands above, "02/23/2004" will be displayed.
how can I get "02/22/2004"?

thank you.
 
Old 02-22-2004, 08:55 PM   #2
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
The "-u" option gives the date for the current UTC time, which is already tomorrow. Pull that out, and it should work.
 
Old 02-22-2004, 08:58 PM   #3
lifetaster
LQ Newbie
 
Registered: Feb 2004
Location: Singapore
Distribution: HP-UX
Posts: 29

Original Poster
Rep: Reputation: 15
thanks, but what i meant is this:

now with

date=`date -u +%m/%d/%Y`
echo "$date"

"02/22/2004" will be displayed.
how to get the string "02/21/2004"?

(date command will give me Mon Feb 23 11:06:04 SST 2004)
(date -u shows: Mon Feb 23 03:06:04 UTC 2004)

Last edited by lifetaster; 02-22-2004 at 09:09 PM.
 
Old 02-23-2004, 06:42 AM   #4
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
I guess your question isn't as clear to me as it is to you... Are you trying to get yesterday's date? You can put a describer into date...
Code:
$ date --date "yesterday" +%Y.%m.%d
2004.02.22
$ date --date "1 day ago" +%Y.%m.%d
2004.02.22
$ date --date "4 day ago" +%Y.%m.%d
2004.02.19
$ date --date "4 days ago" +%Y.%m.%d
2004.02.19
$ date --date "4 month ago" +%Y.%m.%d
2003.10.23
$ date --date "2 year ago" +%Y.%m.%d
2002.02.23
$ date --date "2 year" +%Y.%m.%d
2006.02.23
$ date --date "2 week" +%Y.%m.%d
2004.03.08
 
Old 02-23-2004, 07:05 PM   #5
lifetaster
LQ Newbie
 
Registered: Feb 2004
Location: Singapore
Distribution: HP-UX
Posts: 29

Original Poster
Rep: Reputation: 15
thanks for your information.

as tested, the commands given above seem only work in LINUX not in HP-UX
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
'date' command format Neorio Linux - General 3 01-18-2011 05:18 AM
Trying to do something wierd with the date command cboxall Linux - Newbie 3 07-22-2005 05:24 PM
Trying to do something wierd with the date command cboxall Linux - Newbie 2 07-22-2005 04:45 PM
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 > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:02 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