• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2258
  • Last Modified:

how to convert date from one format to epoch in bash ?

what is the way to convert "Wed Oct 15 04:58:06 2008" to epoch using bash ?
0
beer9
Asked:
beer9
  • 2
  • 2
  • 2
  • +1
1 Solution
 
omarfaridCommented:
the requirement is not clear can you elaborate?
0
 
nognewCommented:
It is possible if you have a GNU date installed.
Ex:
date +%s --date="Wed Oct 15 04:58:06 2008"
gives you:
1224043086

Open in new window

0
 
beer9Author Commented:
I am using BSD, i do not have Gnu date. is there way to accomplish above example in BSD ?
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
nognewCommented:
you can install GNU date. Is that an option for you?
Also you can do it with Perl. Do you want Perl script ?
0
 
TintinCommented:
If you want to do it in pure bash, it's going to be a pretty tedious script.  GNU date really is your best/easiest option.
0
 
TintinCommented:
Actually, you may be able to use the BSD date command like:


date -j -f date -j -f "%a %b %d %T %Y" "Wed Oct 15 04:58:06 2008" +"%s"
0
 
beer9Author Commented:
Excellent!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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