LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-18-2007, 12:25 PM   #1
lindhum
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
Date Format yyymmdd


How do I get the date variable to return format yyymmdd?
 
Old 08-18-2007, 12:46 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 88
I'm assuming that your referring to displaying the date in the shell/ via a shell script. Not sure about yyy (three figure year?) - do you mean yyyy?

You can get a full list of the formatting codes with man date. Today's date, formatted is given by:

date +'<format string>'

The <format string> can include spaces and separator characters such as "/" as well as the formatting codes.

Rob
 
Old 08-19-2007, 02:23 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
You can use a workaround
Code:
dy=$((`date +%Y` - 2000))
d3=`printf "%03d\n" "$dy"`
echo $d3
The first line will get the year and subtract 2000.
The second line creates a string with a minimum of 3 characters.
The last line echoes it to demonstrate.
 
Old 08-19-2007, 05:22 PM   #4
lindhum
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you both.

That got me through, thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 format Bill Jones Linux - Newbie 1 12-23-2006 12:07 PM
date format kalleanka LQ Suggestions & Feedback 9 11-15-2006 12:36 PM
Regarding date Format ancys Programming 4 08-10-2006 06:35 AM
Thunderbird Date Format dotancohen Linux - Software 9 10-15-2005 03:55 PM
Date format Mik LQ Suggestions & Feedback 8 12-05-2004 11:14 AM


All times are GMT -5. The time now is 09:01 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration