Home » Infrastructure » Unix » Date format in Korn Shell script
Date format in Korn Shell script [message #98477] Thu, 18 November 2004 11:48 Go to next message
Pinki
Messages: 5
Registered: September 2004
Junior Member
I have a date varible var. I am stripping the value of var to get each of these values to out1.txt, out2.txt and out3.txt. Now I have 2004 17 and 11 in 0ut3.txt, out2.txt and out1.txt.
I would like to print the dateout variable in the format "2004-11-17" and also store this value in this format.

Filename: test1.sh

var=11/17/2004
echo ${var} | cut -c1-2>out1.txt
echo ${var} | cut -c4-5>out2.txt
echo ${var} | cut -c7-10>out3.txt


Any suggestions?
Re: Date format in Korn Shell script [message #98478 is a reply to message #98477] Thu, 18 November 2004 17:40 Go to previous message
Jai Vrat Singh
Messages: 205
Registered: September 2002
Location: Singapore
Senior Member
From UNIX Man Page:
     mm    Month number

     dd    Day number in the month

     HH    Hour number (24 hour system)

     MM    Minute number

     SS    Second number

     cc    Century minus one

     yy    Last 2 digits of the year number


You can use this to get the date required in the correct format itself as
[jsingh@dv_css5b]:/home/jsingh % date "+%Y-%m-%d"
2004-11-19


But if you want it to be extracted from variable itself then use this
#!/bin/ksh

var=11/17/2004

echo $var| awk -F'/' '{ printf ("%s-%s-%s",$3,$1,$2); }'
Previous Topic: Oracle Integration with Microsoft Active Directory on Unix Platform
Next Topic: script to log into all oracle databases in one unix server
Goto Forum:
  


Current Time: Fri Nov 22 15:37:44 CST 2024