Format dates

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format dates
# 1  
Old 07-29-2002
Format dates

I have a date that is received as text in Jan 1 2002 12:00AM format. Can anyone give me any ideas how to format that in oracle format i.e. 01-JAN-02
# 2  
Old 07-29-2002
Usually you can convert dates in SQL - using the convert command....such as


This converts from Jan 1 2002 12:00AM to 20020101

I'm not sure what all the other formats are....but I would think there's one from this format to 01-JAN-2002. And I'm not sure of your usage of it might not be appropriate.

If you want to do it in could use something like:

the_date='Jan 25 2002 12:00AM'
the_month=`echo $the_date | cut -c1-3 | tr "[:lower:]" "[:upper:]"`
day=`echo $the_date | cut -c5-6`
the_year=`echo $the_date | cut -c8-11`
echo $new_date

Gives: 25-JAN-2002

The only shortcoming of this is that it won't fill the '0' for dates 1-9.....but I'll leave you to figure that out if you want to use it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find hours difference between two dates in given format

I have two dates in below format, how would I find the hours difference between the two dates. Im using AIX and ksh. Current date : Wed May 17 14:34:41 SGT 2017 File date : Thu Apr 27 20:52:41 SGT 2017 (3 Replies)
Discussion started by: simpltyansh
3 Replies

2. Shell Programming and Scripting

How to compare two dates in a specific format ?

Hello, I am not able to find how to compare two dates in '%Y-%m-%d %H:%M:%S,%3N' format i have to two dates as below date1="2016-08-24 09:47:40,444" date2="2016-08-24 10:45:40,567" how to compare these two dates ? I have tried below without success if ; then echo 'yes'; fi ... (6 Replies)
Discussion started by: Ramneekgupta91
6 Replies

3. UNIX for Dummies Questions & Answers

Converting dates to iso format

Hi , i am trying to read a tsv file record by record and change the date column with iso date format. it have different dates with format like mm/dd/yyyy HH:MM:SS EST ,i am trying serarch for the date format lke this yyyy-mm-dd HH:MM:SS EST and replace to it if dosent match that format . Any... (2 Replies)
Discussion started by: vikatakavi
2 Replies

4. Solaris

Date after 5 dates in YYYYMMDD format

Hi Experts, How to get date 5 days after current date in YYYYMMDD format? How do we compare date in YYYYMMDD format? Thanks (1 Reply)
Discussion started by: needyourhelp10
1 Replies

5. Shell Programming and Scripting

Dates not comparing correct even the same format

I have the date of the file passed into a variable also current date formatted same passed into a separate variable and compare the two with an if statement and statement always comes up false. Even though I verified the dates. Any help would be awesome. Filecrtdate=`ls -l $i | awk '{print... (19 Replies)
Discussion started by: coderanger
19 Replies

6. UNIX for Advanced & Expert Users

fetch dates for last 36 days in format yyyy-mm-dd

can anyone please suggest me some ideas for writing a korn shell script which will go back to 36 days from current day and print each day (incremented by 1) in the format yyyy-mm-dd until the current day. Thanks Mark (7 Replies)
Discussion started by: pavan_test
7 Replies

7. Shell Programming and Scripting

change date format and then compare dates

I have filenames filenameA_fg_MMDDYY.tar.gz filenameASPQ_fg_MMDDYY.tar.gz filenameAFTOPHYYINGH_fg_MMDDYY.tar.gz filenameAGHYSW_fg_MMDDYY.tar.gz My requiremnt needs to extract date which is in MMDDYYand change it into YYYYMMDD format. I have done the following: filedate=`echo... (5 Replies)
Discussion started by: RubinPat
5 Replies

8. Shell Programming and Scripting

Date difference between 2 dates in 'yyyy-mm-dd hh:mm:ss' format

Hi all, I know this may have already been asked but hey ho... i have two dates in the 'yyyy-mm-dd hh:mm:ss' format. '2009-01-03 01:00:00' '2009-04-05 00:00:00' How can i, in shell script determine their differences? Please note, the time may not be available, so please suggest both... (4 Replies)
Discussion started by: muay_tb
4 Replies

9. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. UNIX for Dummies Questions & Answers

converting 6 digit column to dates format

Hi everyone, I have problem where I need to convert numbers to date format and then figure out what is less than or equal to specific date, the data comes out of a report in the following format 071205 141005 091205 111105 051005 141005 261005 181005 so I need to firstly run through... (15 Replies)
Discussion started by: Gerry405
15 Replies
Login or Register to Ask a Question