LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 01:40 PM   #1
RudyMartin
Member
 
Registered: Nov 2011
Location: Argentina
Distribution: Slackware, Debian
Posts: 40

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 01:42 PM.
 
Old 12-01-2011, 03:53 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

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


Reply



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

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

All times are GMT -5. The time now is 04: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
Open Source Consulting | Domain Registration