LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-14-2008, 11:18 PM   #16
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235

this command doesn't reset the time right?:
Code:
date +%a -d $1-$2-$3
. i haven't seen that
 
Old 03-15-2008, 12:27 AM   #17
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you use:
date +%a -d "$day/$month/$year"
This will display the day of the week on that date. I changed the variable names to indicate what they represent.
Code:
day=10 month=12 year=2007
> date +%a -d "$day/$month/$year"
Fri
The computers date & time settings won't be changed.

Your form uses the year for the first variable:

Code:
day=10 month=12 year=2007
jschiwal@hpamd64:~> date +%a -d "$year-$month-$day"
Mon
With this form of date, dates are in alphabetical order.

Last edited by jschiwal; 03-15-2008 at 12:28 AM.
 
Old 03-15-2008, 12:43 AM   #18
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Thanks I know what you mean. In order for the script to work, you'll also need to know what weekday name of a specific date. So I thought of the external date command and looked for it's syntax and I found none and that is why i referred to other functions in php or perl. I should have looked a little bit further in date's options. my mistake again .
 
Old 03-15-2008, 01:22 AM   #19
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by konsolebox View Post
this command doesn't reset the time right?:
Code:
date +%a -d $1-$2-$3
. i haven't seen that
No. The -d option just means "use a date/time defined in the argument to this parameter", and the +%a just specifies that the output format is using the %a format string (week day). $1 $2 and $3 are the values of the first three arguments to the function - called the "positional parameters" in shell talk. I wrote the function to expect the year, month and day, so putting them together with hyphens between makes a date which the date program can understand, e.g. if the positional parameters are 2007, 02, and 12, the string passed to the date command would be "2007-02-12".

The date command can be used to set the system date, but only if you use the -s (or --set) option, and have sufficient privileges to do it (i.e. you are root).

You should read the date manual page (enter terminal, type "man date"). Manual pages look a little confusing at first, but they all follow more or less the same format, and once you have a little experience reading them, you will be able to answer this sort of question for ourself with ease, and a lot more quickly than by asking others.

To my mind, the really nice thing about manual pages is that they are arranged like a tabloid news story. The first line tries to encapsulate the general gist of the page (i.e. a one line summary of that the subject of the page is), then there's a short overview description and so o, getting more and more detailed towards the end of the page.

Most manual pages have the same main sections, which are printed in CAPTIALS at the start of a line. If your manual browser is set up as most are, using less as a pager, you can search for a section, like OPTIONS easily, just by hitting / and then typing
Code:
^OPT
.
The ^ means "start of line" in less searches.

Last edited by matthewg42; 03-15-2008 at 01:25 AM.
 
Old 03-15-2008, 01:58 AM   #20
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
There is also the info manual which does include examples. It really helps to see an example that has a format argument.
 
Old 03-15-2008, 03:02 AM   #21
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
i did read the manual page of date .. i always do that since i'd prefer and find it quicker to do 'man date' than 'date --help' .. i just have not looked good enough though. btw we can also have our own way to look for the days of the week without depending on 'date'.. i know a way to do this and it's not really big.. if i'll have the time.. i'll build the script.. just for fun

Quote:
Originally Posted by jschiwal View Post
There is also the info manual which does include examples. It really helps to see an example that has a format argument.
what is not good in info pages is that they are just similar to manual pages like sed.. so sometimes i don't look at them anymore

Edit:
to make things clearer i just looked at these:
Code:
       date [OPTION]... [+FORMAT]
       date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
and not this:
Code:
       -d, --date=STRING
	      display time described by STRING, not `now'
obviously in the first ones you won't see an immediate info about being able to add a custom date.. adding a custom was what i was looking for.

Last edited by konsolebox; 03-15-2008 at 03:12 AM.
 
Old 03-15-2008, 08:45 AM   #22
hro
LQ Newbie
 
Registered: Jan 2008
Distribution: OpenSuse 10.3, SLED 10 SP2, Ubuntu 8.04 and 9.04
Posts: 23

Rep: Reputation: 15
'info date' info is much more complete than 'man date'
 
  


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
find out the files created on a particular date. ZAMO Linux - General 3 02-08-2008 01:38 AM
Is there a way to find recently created/edited files without using find? BrianK Linux - General 2 10-15-2007 09:41 PM
find command : finding files that are created within last 24 hours Fond_of_Opensource Linux - Newbie 1 11-06-2006 03:47 AM
Find all files created or modified between 2 times MicahCarrick Linux - Software 3 06-29-2006 04:22 PM
Using FIND to locate files created between certain dates billybobjoe1984 Programming 6 07-23-2005 06:07 PM

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

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

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