The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Formatting Date Variable (Pls help) gmoth Shell Programming and Scripting 1 02-19-2008 09:03 AM
formatting date for different locales Aeon UNIX for Dummies Questions & Answers 2 08-22-2007 09:39 PM
date formatting mgirinath Shell Programming and Scripting 4 07-08-2006 02:08 AM
Formatting Date (adding a month) devid UNIX for Dummies Questions & Answers 4 01-18-2006 07:31 AM
Formatting date radhika03 Shell Programming and Scripting 2 12-13-2005 11:56 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-12-2007
Registered User
 

Join Date: Jan 2007
Posts: 22
Date formatting

Running bash how do I input the date in the command line like 3/20/90 and get an output formmated like March, 20 1990.
Reply With Quote
Forum Sponsor
  #2  
Old 01-15-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 798
this works for me:

Code:
[ysawant@anamika ysawant]$ date +'%B, %d %G' --date="3/20/90"
March, 20 1990
[ysawant@anamika ysawant]$
Reply With Quote
  #3  
Old 01-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 22
thanks. that worked. do you know how I would make it work so if 13 was inputed as the month it would print an error?
Reply With Quote
  #4  
Old 01-15-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
An error like this?
Code:
$ date +'%B, %d %G' --date="13/20/90"
date: invalid date `13/20/90'
You could also do something like this:
Code:
$ date +'%B, %d %G' --date="13/20/90" 2>/dev/null || echo "ERROR"
ERROR
$ date +'%B, %d %G' --date="3/20/90" 2>/dev/null || echo "ERROR"
March, 20 1990
Cheers
ZB
Reply With Quote
  #5  
Old 01-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 22
when i input a month of 13 now i get it bumped to january. i do the input from the command line, so i need to read the month from there and determine if it is over 12 and display an error stating that the month inputed does not exist.
Reply With Quote
  #6  
Old 01-15-2007
Registered User
 

Join Date: Dec 2006
Location: CA,United States
Posts: 174
#! /usr/bin/ksh
echo -p "Enter the Input date format : \c"
read t
m=`echo $t|cut -d "/" -f1`
if [ $m -lt 13 ]; then
date +'%B, %d %G' --date="$t"
else
echo "Not a Valid Month"
exit 0
fi
Reply With Quote
  #7  
Old 01-16-2007
Registered User
 

Join Date: Jan 2007
Posts: 22
yeah not looking for an input line want it right off the command line. (shell scriptname date)

i'm trying to use IFS and separate the input by the "/". script currently looks like...
#!/bin/bash

{ [ $# -eq 1 ] &&
[ -d "$1 ]; } || {
echo "Must Input Date: mm/dd/yyyy"
exit 1
}

FDATE="$1"
OLDIFS="$IFS"
IFS="/"
set $1
IFS="$OLDIFS"


get these errors...
spell_date: line 13: unexpected EOF while looking for matching `"'
spell_date: line 14: syntax error: unexpected end of file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0