Convert date arg to sql date


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert date arg to sql date
# 1  
Old 05-02-2013
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
# 2  
Old 05-02-2013
Code:
[user@host ~]$ x=20130501
[user@host ~]$ echo "${x:0:4}-${x:4:2}-${x:6}"
2013-05-01
[user@host ~]$

# 3  
Old 05-02-2013
Code:
$fulldate=20130430
bdate=`{$fulldate:0:4}-{$fulldate:4:2}-{$fulldate:6}`
echo $bdate

does not seem to work when I try to assign it as var

Last edited by Franklin52; 05-03-2013 at 03:16 AM.. Reason: Code tags
# 4  
Old 05-02-2013
Quote:
Originally Posted by tasmac
$fulldate=20130430
bdate=`{$fulldate:0:4}-{$fulldate:4:2}-{$fulldate:6}`
There should be no dollar before "fulldate".
Code:
fulldate=20130430

Dollar should be outside the curly braces.
Code:
bdate=`${fulldate:0:4}-${fulldate:4:2}-${fulldate:6}`

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 05-02-2013
works fine now
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

2. 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

3. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 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. Solaris

calculate sum size of files by date (arg list too long)

Hi, I wanted a script to find sum of files for a particular date, below is my script ls -lrt *.req | nawk '$6 == "Aug"' | nawk '$7 == "1"'| awk '{sum = sum + $5} END {print sum}' However, i get the error below /usr/bin/ls: arg list too long How do i fix that. Many thanks before. (2 Replies)
Discussion started by: beginningDBA
2 Replies

6. Shell Programming and Scripting

Convert date

If I pass the value in the form YYYY/MM/DD(20100719) how to convert in the form 19\/Jul\/2010 (1 Reply)
Discussion started by: sandy1028
1 Replies

7. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

8. 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

9. UNIX for Dummies Questions & Answers

Date convert Help

Hi, I need to convert a char date to the datetime format for a table in sybase. I don't know how to do it, can anyone help me on this ? Thanks a lot !!!! :) (2 Replies)
Discussion started by: nzq71k
2 Replies
Login or Register to Ask a Question