LinuxQuestions.org
Help answer threads with 0 replies.
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 02-25-2010, 11:26 PM   #1
sumeet inani
Member
 
Registered: Oct 2008
Posts: 898
Blog Entries: 26

Rep: Reputation: 49
using date command


I am using ubuntu 8.04.
I read the man page of date.
I wanted to change just the second part of my current time so I ran
# date +%S -s "35"
OUTPUT
date: invalid date `35'

Does it mean that format for setting date should contain atleast hour minute & second though for displaying , just the second part
$date +%S
OUTPUT
06
works well.
 
Old 02-25-2010, 11:55 PM   #2
mesiol
Member
 
Registered: Nov 2008
Location: Lower Saxony, Germany
Distribution: CentOS, RHEL, Solaris 10, AIX, HP-UX
Posts: 731

Rep: Reputation: 137Reputation: 137
Hye

you have to specify a valid date format a mentioned in the man page.

Code:
date [MMDDhhmm[[CC]YY][.ss]]
You cannot combine specific output format parameters like +%S with parameters to set new date.
 
Old 02-26-2010, 12:00 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,462
Blog Entries: 6

Rep: Reputation: 51
Use:

Code:
date -s "Feb 26 11:30:29"
 
Old 02-26-2010, 12:34 AM   #4
sumeet inani
Member
 
Registered: Oct 2008
Posts: 898
Blog Entries: 26

Original Poster
Rep: Reputation: 49
I read http://www.cyberciti.biz/faq/howto-s...ommand-prompt/ which says I can set day,month,year,time or day,month,year or just 'time'(using %T).
I was wondering if I can set just the second part of time ?
Like I can output the second part of time as mentioned in my first post.

Last edited by sumeet inani; 02-26-2010 at 12:37 AM.
 
Old 02-26-2010, 01:09 AM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,501

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
I see what you expect. If date doesn't accept that, you have to feed it HH:MM:SS format.

date +%T -s "$(date +%R):35"
This will feed a valid time string into date -s. If date can handle setting the time using the %T parameter, this will work. Untested, I don't want to set the time on the machine I am currently at.

jlinkels
 
1 members found this post helpful.
Old 02-26-2010, 02:27 AM   #6
sumeet inani
Member
 
Registered: Oct 2008
Posts: 898
Blog Entries: 26

Original Poster
Rep: Reputation: 49
Thanks jlinkels
As mentioned earlier I was trying to avoid typing hour & minute while setting second.
You accomplished that by inputing current hour , minute through date command.
Smart move.

I also conclude that so many options for format are for displaying & not all of them can be used individually ( means singly like %S alone gave error ) while setting time ( obviously as root ) .
Tell me if I am wrong ?
 
Old 03-31-2010, 09:14 PM   #7
Mighty Phlabaud
LQ Newbie
 
Registered: Jul 2008
Location: washington
Distribution: Red-Hat 5.1
Posts: 1

Rep: Reputation: 0
... ciao:

try this.

date "+%a %b %d %H:%M:35 %Z %Y"

hope that helps ...
 
Old 04-01-2010, 05:46 AM   #8
sumeet inani
Member
 
Registered: Oct 2008
Posts: 898
Blog Entries: 26

Original Poster
Rep: Reputation: 49
date "+%a %b %d %H:%M:35 %Z %Y"
This command does not set date but displays in following format
Thu Apr 01 16:11:35 IST 2010
A little explanation for others
Code:
%a week-day
%b month
%d day of month
%H hour 0-23
%M minute 0-59
%Z time zone
%Y year
 
Old 04-01-2010, 05:56 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by sumeet inani View Post
I am using ubuntu 8.04.
I read the man page of date.
I wanted to change just the second part of my current time so I ran
# date +%S -s "35"
OUTPUT
date: invalid date `35'
How about date --date='35 seconds' to set the date to now + 35 seconds (not tested)?
 
Old 05-06-2010, 05:40 AM   #10
sumeet inani
Member
 
Registered: Oct 2008
Posts: 898
Blog Entries: 26

Original Poster
Rep: Reputation: 49
date --date='35 seconds' does not set date 35 seconds ahead but simply displays what would be time 35 seconds in future.

jinkels suggested
date +%T -s "$(date +%R):35"
If I want to save trouble of typing hour minute while setting time.
This worked well.
 
  


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
date command miran_shahverdyan Linux - General 4 10-14-2009 06:59 AM
date command is not accepting monu Linux - General 7 10-25-2007 09:20 AM
command for date DarReNz Solaris / OpenSolaris 7 09-05-2006 09:53 AM
date command aetucker1 Linux - General 3 01-21-2005 12:57 PM
help with Date command in script icw_sec Programming 6 01-06-2004 11:02 AM


All times are GMT -5. The time now is 05:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration