formatting date in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting formatting date in ksh
# 1  
Old 12-09-2008
formatting date in ksh

hi all,
in ksh, how do i format date so it includes hour and minute ?? i am trying the following command :

date +%Om/%Od/%Oy%OH:%M

but it displays the hour and minute concatenated with the day/month/year e.g 12/10/0814:08

when i want the output to be

12/10/08 14:08

i tried `date +%Om/%Od/%Oy %OH:%M` but that just leaves the time portion out and displays date only i.e 12/10/08.


thanks in advance.
# 2  
Old 12-09-2008
simple Smilie!!
put a space inbetween year and hour
Code:
date +"%Om/%Od/%Oy %OH:%M"

# 3  
Old 12-09-2008
nope that doesnt work as i tried that already as per my original post. However the below works :


date '+%m/%d/%y %H:%M:%S'


output :

12/10/08 14:23:53
# 4  
Old 12-09-2008
Quote:
Originally Posted by cesarNZ
nope that doesnt work as i tried that already as per my original post. However the below works :


date '+%m/%d/%y %H:%M:%S'


output :

12/10/08 14:23:53
oh common it will work i can bet on that.. you might have typed it wrong somewhere and your desired output can be possible by simply
Code:
 
home> date +"%D %T"
12/10/08 06:58:45
home> date +"%Om/%Od/%Oy %OH:%M"
12/10/08 06:59


Last edited by vidyadhar85; 12-09-2008 at 09:40 PM..
# 5  
Old 12-09-2008
Which date are you using? Modern versions of ksh have a builtin date which has slightly different semantics than the standalone date utility. Try date --man. If it displays information, then you are using the builtin date.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh file formatting

Hi. If I have a txt file in the following format: option1=123 option2=abc option3=321 How do I convert it with KSH into the following format (with the additional prefixed string): ${filename},::option1=123,option2=abc,option3=321 Many thanks (3 Replies)
Discussion started by: user052009
3 Replies

2. UNIX for Dummies Questions & Answers

Print start date to end date, given $1 & $2 in ksh

Dear all, I have an user passing 2 parameter 31/03/2015 and 02/04/2015 to a ksh script. How to print the start date to end date. Expected output is : 31/03/2015 01/04/2015 02/04/2015 Note : 1. Im using aix and ksh 2. I have tried to convert the given input into a date, didnt... (0 Replies)
Discussion started by: mr.rajaravi
0 Replies

3. Shell Programming and Scripting

Formatting output using awk in ksh

:oi was trying to write a script to format output of a command in ksh which has output as below: so i used : to get which i require at all times. But problem occurs when status part changes. above output i get when status is SU (success).If the status is IN (inactive), output of... (1 Reply)
Discussion started by: pr5439
1 Replies

4. UNIX for Dummies Questions & Answers

Unable to convert date into no. using date -d +%s syntax in ksh shell

hi friends, I m trying to write a script which compares to dates. for this i am converting dates into no using synatx as below v2=`date | awk '{print $2,$3,$4}'` v3=`date +%s -d "$v2"` this syntax is working in bash shell ,but fails in ksh shell. please suggest on this. (12 Replies)
Discussion started by: Jcpratap
12 Replies

5. Shell Programming and Scripting

Text Formatting using printf[ksh]

Hi All, I am attempting to create a fixed length tilde delimited file using printf. The variables are initialized to fixed length blank spaces a=' ' b=' ' c=' ' d=' ' Sometimes the variable might contain values and sometimes they are... (5 Replies)
Discussion started by: angie1234
5 Replies

6. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

7. Shell Programming and Scripting

How to Get 60 days Old date from current date in KSH script

Hi i am writing a cron job. so for it i need the 60 days old date form current date in variable. Like today date is 27 jan 2011 then output value will be stote in variable in formet Nov 27. i am using EST date, and tried lot of solution and see lot of post but it did not helpful for me. so... (3 Replies)
Discussion started by: Himanshu_soni
3 Replies

8. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies

9. Shell Programming and Scripting

date formatting

Date format MM/DD/YYYY required is YYYYMMDD, I tried using sed but could not get it any help please. (4 Replies)
Discussion started by: mgirinath
4 Replies

10. UNIX for Dummies Questions & Answers

Help on formatting a number in ksh

I don't know if this is possible. Still fairly new to ksh scripting. Here is what I am wanting to do with my output. change the following From: 1349870987 To: 1,349,870,987 in my output. How do I do this? Thanks, S (1 Reply)
Discussion started by: Speide
1 Replies
Login or Register to Ask a Question