Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2292
  • Last Modified:

Convert string to date

Hi all,

how do i convert user input (which i assume the example below is as string ) to unix date format?

echo "please enter date [dd/mm/yy]:
read answer

I can't use date -d option as my unix is sun solaris n does not support that.
It only supports

date [-u] mmddHHMM[[cc]yy][.SS]
 date [-u] [+format]
 date -a [-]sss[.fff]

any idea?



0
c00kie88
Asked:
c00kie88
  • 2
1 Solution
 
omarfaridCommented:
you can get rid of / in the input string using

echo $answer | awk -F'/' '{ print $1 " "  $2 " "  $3 }' | read d m y

then

date $m$d0000$y

 
0
 
omarfaridCommented:
Why given grade B?
0
 
TintinCommented:
Was your intention to reset the system date/time?  I got the impression you were simply trying to convert one date format to another.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now