![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.
|
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
this works for me:
Code:
[ysawant@anamika ysawant]$ date +'%B, %d %G' --date="3/20/90" March, 20 1990 [ysawant@anamika ysawant]$ |
|
#3
|
|||
|
|||
|
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?
|
|
#4
|
||||
|
||||
|
An error like this?
Code:
$ date +'%B, %d %G' --date="13/20/90" date: invalid date `13/20/90' 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 ZB |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
#! /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 |
|
#7
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |