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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-07-2007, 09:29 PM
|
#1
|
|
LQ Newbie
Registered: Jun 2007
Posts: 17
Rep:
|
date format
Hi,
I am having problem with creatng date formate: YYYYMMDD .
My code is: date +%Y%m%d but its not working it. I checked %Y only displays current year not past year. suppose if i enter my date: 18240804 it doesn't accept it. IT only takes 20070804.. not past years. What is date -s do?
Thanks
|
|
|
|
10-07-2007, 09:49 PM
|
#2
|
|
LQ Newbie
Registered: Jun 2007
Posts: 17
Original Poster
Rep:
|
for example:
#!/bin/bash
c_date=`date +%Y`
read -p echo "enter year" year
if......
echo "working"
else
echo "not working"
fi
enter year:2005
not working
enter year: 2007
working!
So my point is %Y is only for current year not for past year. I want to create script which accepts past years day and months like this: YYYMMDD. I read man page i couldn't find out what is date -s ? please provide me some example and with past year.
Thanks
|
|
|
|
10-08-2007, 01:20 AM
|
#3
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,261
|
From the man page:
date - print or set the system date and time
I don't think it does what you want ie check random strings for validate dates (if that's what you meant).
|
|
|
|
10-08-2007, 02:32 AM
|
#4
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,899
|
The GNU date command accept the -d option to specify a date other than the current date. From the info page:
Quote:
`-d DATESTR'
`--date=DATESTR'
Display the date and time specified in DATESTR instead of the
current date and time. DATESTR can be in almost any common
format. It can contain month names, time zones, `am' and `pm',
`yesterday', etc. For example, `--date="2004-02-27
14:19:13.489392193 +0530"' specifies the instant of time that is
489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a
time zone that is 5 hours and 30 minutes east of UTC. *Note Date
input formats::.
|
Check the section "Note Date input formats" for details on how to specify the past date. The following are all working examples:
Code:
date -d "23 June 1867" +%Y%m%d
date -d "Jul 11, 1968 - 3 days" +%Y%m%d
date -d "2 days ago" +%Y%m%d
and so on.
Last edited by colucix; 10-08-2007 at 02:35 AM.
|
|
|
|
10-08-2007, 03:48 AM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,916
|
I'm afraid that date won't handle dates before 1902
Code:
$ date -d 1902-04-08
Tue Apr 8 00:00:00 GMT 1902
$ date -d 1901-04-08
date: invalid date `1901-04-08'
Not that I can see any useful application to that,
mind you....
Cheers,
Tink
|
|
|
|
10-08-2007, 04:26 AM
|
#6
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,899
|
Quote:
Originally Posted by Tinkster
I'm afraid that date won't handle dates before 1902
|
Uh... mine seems to work...
Code:
$ date -d 1902-04-08
Tue Apr 8 00:00:00 CET 1902
$ date -d 1901-04-08
Mon Apr 8 00:00:00 CET 1901
I have date version:
Code:
date (GNU coreutils) 5.97
I will investigate! 
Cheers
|
|
|
|
10-08-2007, 10:47 AM
|
#7
|
|
LQ Newbie
Registered: Jun 2007
Posts: 17
Original Poster
Rep:
|
hi
Thanks
I will try that
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
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 |
|
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 |
|
Date format
|
Mik |
LQ Suggestions & Feedback |
8 |
12-05-2004 10:14 AM |
All times are GMT -5. The time now is 11:47 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|