Newbie convert date ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Newbie convert date ksh
# 1  
Old 03-14-2006
Newbie convert date ksh

If I have
start = 02282006;
end = 03152006;

How do I get
startdate = 02/28/2006;
enddate = 03/15/2006;

Thanks,
# 2  
Old 03-15-2006
Code:
echo "02282006" | sed -e 's_\(..\)\(..\)\(....\)_\1/\2/\3_g'

or
Code:
start=02282006;
echo "$start" | sed -e 's_\(..\)\(..\)\(....\);_\1/\2/\3;_g'

# 3  
Old 03-15-2006
There are a few ways. Simplest is to use 'cut -c'. Check the man page for more details on this command.
# 4  
Old 03-15-2006
Or, if you want to use shell built-ins only you can reformat the date using fixed length variables:

Code:
function dateformat
{
typeset -L2 d=$1
typeset -R4 y=$1
typeset -R6 t=$1
typeset -L2 m=$t
print ${d}/${m}/${y}
}

print "startdate = $(dateformat 02282006)"
print "enddate = $(dateformat 03152006)"

cheers
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

2. Shell Programming and Scripting

Convert date arg to sql date

Doing a bcp load to sybase and need to convert datearg which comes in as 20130501 to 2013-05-01 which is the best way to do this (4 Replies)
Discussion started by: tasmac
4 Replies

3. Shell Programming and Scripting

How to convert string(variable) into date( epoch) in ksh on HPUX machine?

Hi all, I have used a bash script which ultimately converts a string into date using date --date option: DATE=$DATE" "$TIME" "`date +%Y` //concatenating 2 strings TMRW_DATE=`date --date="$DATE" +"%s"` //applying date command on string and getting the unixtime Please use code tags... (7 Replies)
Discussion started by: Rashu123
7 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

newbie: writing ksh shell problem

my default profile is using ksh, I tried to write a simple scripts and I had issues, below is my scripts: $ more if_num.ksh USAGE="usage: if_num.ksh" print -n "Enter two numbers: " read x y if ((x=y)) then print "You entered the same number twice." when I tried to executed the... (6 Replies)
Discussion started by: matthew00
6 Replies

6. Shell Programming and Scripting

Please help - newbie (date)

Hi I need help to write a script to do following: Sample Input file1: 07-01-08 08:48:07:982 INFO .... 07-01-08 08:49:07:982 DETAIL ..... 07-01-08 08:50:14:982 INFO ..... 07-01-08 08:51:23:982 DETAIL ..... 07-01-08 08:52:57:982 INFO ..... 07-01-08 08:53:01:982 DETAIL ..... 07-01-09... (1 Reply)
Discussion started by: mel_2008
1 Replies

7. Shell Programming and Scripting

convert Julian date to calender date

Hi, I have script in unix which creates a julian date like 126 or 127 I want convert this julian date into calender date ex : input 127 output 07/may/2007 or 07/05/2007 or 07/05/07 rgds srikanth (6 Replies)
Discussion started by: srikanthus2002
6 Replies

8. Shell Programming and Scripting

Newbie problem with ksh script

Hi all, I have a directory have all of the .stat and .dat file : they are is a pipe separate flat file. Example: log-20061202.stat contain 1st line and last line of log-20061202.dat with record count of that day. Example: Total record = 240 Tom|02-12-2006|1600 W.Santa... (18 Replies)
Discussion started by: sabercats
18 Replies

9. Shell Programming and Scripting

KSH Script/FTP (NEWBIE)

I trying to write a ksh script (without the help of the Kermit libraries) which connects to a ftp server and checks if the file "KEI.done" exists. If the file exists it print "files is there" if it doesnt exist it prints "file is not there". (the print statements will later be replaced with code to... (2 Replies)
Discussion started by: mike509123
2 Replies
Login or Register to Ask a Question