Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-18-2007, 12:25 PM   #1
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
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
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.

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
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
LQ Newbie
Registered: Aug 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Thank you both.

That got me through, thanks.


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:03 AM.

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