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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
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
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
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
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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
|
|
|
All times are GMT -5. The time now is 06:53 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
|
|