Convert date to Unix format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert date to Unix format
# 8  
Old 04-05-2011
Quote:
Originally Posted by bakunin
This is a questionable advice: it will solve the problem but at the expense of portability. Scripts should be written do expect the common minimum of utilities offered by the OS.
A KSH or Perl script is hardly portable in that sense, though it's potentially easier to install Perl or a recent KSH than GNU date.

Date math/conversion/formatting, I think, remains a pretty big pothole.
# 9  
Old 04-06-2011
I never heard of ksh93, how to use it as i tried it on solaris 10 but not found
# 10  
Old 04-06-2011
Quote:
Originally Posted by yahyaaa
I never heard of ksh93, how to use it as i tried it on solaris 10 but not found
Korn shell (ksh) usually comes in a 1988 or a 1993 version.

AFAIK Solaris has a ksh93 available.

I hope this helps.

bakunin
# 11  
Old 04-18-2011
Quote:
Originally Posted by yahyaaa
Thanks... What if I need it for predefined time ?

---------- Post updated at 10:25 AM ---------- Previous update was at 10:20 AM ----------

Thank you

---------- Post updated at 10:26 AM ---------- Previous update was at 10:25 AM ----------

I never heard of ksh93, how to use it as i tried it on solaris 10 but not found

if you want to use Perl for predefined date you can use below code:-

Code:
#!/usr/bin/perl -l

use Date::Parse;
print str2time("Mon Apr 18 16:45:00 UTC 2011"); #1303145100
print str2time("04/18/2011 07:45:00PM"); #1303145100
print str2time("2011-04-18 19:45:00") ; ##local time zone is Asia/Amman which is GMT+3 #1303145100
print str2time("2011-04-18 16:45:00 UTC") ; #1303145100
print str2time("2011-04-18 16:45:00 GMT") ; #1303145100
print str2time("2011-04-19 01:45:00 JST") ; #1303145100

Note:- JST time is Japan standard time (UTC/GMT+9), and UTC is same as GMT time.

SmilieSmilieSmilieSmilieSmilieSmilie
This User Gave Thanks to ahmad.diab For This Post:
# 12  
Old 04-20-2011
Thanks a lot ...its working
# 13  
Old 04-20-2011
Quote:
Originally Posted by fpmurphy
Using ksh93, which is available on Solaris 10 as /usr/bin/ksh93 and on Solaris 11 as /usr/bin/ksh:
I do not have /usr/bin/ksh93 on either update 4 or update 8. What revision of Solaris 10 are you using? I do see /usr/dt/bin/dtksh which claims to be based on ksh 93 but...
Code:
$
$ /usr/dt/bin/dtksh
$ printf "%(%s)T\n"  "2011-05-15 18:00:00 UTC"
/usr/dt/bin/dtksh: printf: T: unknown format specifier
$ set -o emacs
$ Version M-12/28/93d

I typed a cntl-V after the "set -o emacs" to get the version info.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert date in dd mm yyyy format to UNIX timestamp

Hello All, I have a date in DD/MM/YYYY format. I am trying to convert this into unix timestamp. I have tried following: date -d $mydate +%s where mydate = 23/12/2016 00:00:00 I am getting following error: date: extra operand `+%s' Try `date --help' for more information. ... (1 Reply)
Discussion started by: angshuman
1 Replies

2. Shell Programming and Scripting

Convert Date Format

Hello, I want to change the format of date value in variable. e.g. cur_date = '2013/03/13 14:24:50' (yyyy/mm/dd hh24:mi:ss) I want to change this to '13-MAR-2013 14:24:50 Following code coverts the current date to format I am looking for. But I do not know how this can be done for a date... (8 Replies)
Discussion started by: cartrider
8 Replies

3. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

4. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

5. Shell Programming and Scripting

convert date format

I've been using this thread: https://www.unix.com/shell-programming-scripting/58675-change-date-dd-mmm-yyyy-mm-dd-yyyy.html and https://www.unix.com/shell-programming-scripting/14655-changing-yyyy-mm-dd-ddmmyy.html and this code: on this format: 05/16/2008 18:30:49 Installation 48985and I'm... (3 Replies)
Discussion started by: dba_frog
3 Replies

6. Shell Programming and Scripting

To convert a date(in string format) to unix timestamp

Hi All, I have a string like below. "Mar 31 2009" . I want to convert this to unix time . Also please let me know how to find the unix time for the above string minus one day. For Eg. if i have string "Mar 31 2009" i want to find the unix time stamp of "Mar 30 2009". Thanks in advance,... (11 Replies)
Discussion started by: girish.raos
11 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 unix date to readable format

Dear Experts, I need your help to convert a unix date and time format number in to readable format like dd/mm/yyyy . I have a text file of more than 10,000 records and it is like NAME DATE1 COUNTRY DATE2 ABD 1223580395699 USA 1223580395699... (3 Replies)
Discussion started by: shary
3 Replies

9. UNIX for Dummies Questions & Answers

Convert date format

Hi All, Need your help in converting a date format in ksh. I'm currently working on SUN os where my script is getting a date from a table. The result returns to ksh in this format: 17-JUL-08 How do i convert this string to a date format like yyyymmdd? I tried #!/bin/ksh d="17-JUL-08"... (5 Replies)
Discussion started by: agathaeleanor
5 Replies

10. Shell Programming and Scripting

convert mmddyy date format to ccyyddd format??

hi, for reading a cobol indexed file i need to convert "mmddyy" date format to "ccyyddd" format. i checked the datecalc and other scripts but couldnt modify them to cater to my need:(... The datecalc gives an output which i believe is the total days till that date, but i want to convert it... (2 Replies)
Discussion started by: Bhups
2 Replies
Login or Register to Ask a Question