LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 11:25 AM   #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, 11:46 AM   #2
Robhogg
Member
 
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.

Rob
 
Old 08-19-2007, 01:23 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

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, 04: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:49 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
Open Source Consulting | Domain Registration