Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-01-2011, 01:40 PM   #1
LQ Newbie
Registered: Nov 2011
Location: Argentina
Distribution: Slackware
Posts: 25

Rep: Reputation: Disabled
bash: setting date with a custom formatting

as usual been reading several web pages and I can not find whats wrong with this command:

if as root I do

date --set="20111201" +"%Y%m%d"

it works, but if I do:

root@darkstar:/home/rudy# date --set="2011120116" +"%Y%m%d%H"
date: invalid date `2011120116'

What I want is to create a user script to change only the date, not the time.

this is the complete script I have done so far:

echo -n sudo date +%Y%m%d%H%M -s>resultado                                                                                                     
cat resultado                                                                                                                                  
echo -n $1$2$3>>resultado                                                                                                                      
cat resultado                                                                                                                                  
date +%H%M>>resultado                                                                                                                          
cat resultado                                                                                                                                  
chmod +x resultado                                                                                                                             
quick update:
root@darkstar:/home/rudy# date +"%Y%m%d%H"

it works. something is wrong with the --set option, a bug may be?

Last edited by RudyMartin; 12-01-2011 at 01:42 PM.
Old 12-01-2011, 03:53 PM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652Reputation: 652
'--set' takes a string in human readable format.. see 'info date' for examples.


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 formatting from stat command tensigh Programming 10 08-30-2010 04:13 AM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
using ps with the u option and custom formatting Leo Simon Linux - Software 1 05-29-2009 12:25 PM
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
formatting date output grob115 Linux - Newbie 2 01-28-2006 08:03 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration