LinuxQuestions.org
Visit Jeremy's Blog.
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 12-01-2011, 02:40 PM   #1
RudyMartin
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:

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

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

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

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


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


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