LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   Convert Normal Date to Unix Time (https://www.linuxquestions.org/questions/aix-43/convert-normal-date-to-unix-time-556343/)

gbratig 05-24-2007 07:52 AM

Convert Normal Date to Unix Time
 
Hello, i need some help, i'm creating a script and i need to convert normal date (24/05/07) in unix time, i see some web sites with calculators, but i need to put the code in my shell script. In the first time i thought that i will found that in google jeje, but i only found the inverse, unix time to normal date. Somebody can help me?. Thanks a lot.

Wells 05-24-2007 08:32 AM

After a quick google, I found the following page that should point you in the right direction, using perl...

http://www.unixreview.com/documents/s=1344/ur0307g/

mudman69 05-30-2007 11:06 AM

Hey gbratig, Can you point me to the site where you saw the Epoch to normal date conversion?

gbratig 05-31-2007 01:32 AM

http://unixepoch.com/

crabboy 06-01-2007 09:37 AM

compile this and call it from your script. You'll have to setup a template file, you can probably create it in your script and delete it before the script finishes.
Code:

#include <stdio.h>
#include <time.h>

main( int argc, char * argv[] )
{
  struct tm * timestruct;
  time_t epochtime;

  if ( getenv("DATEMSK") == 0 )
  {
      printf("\nSet environment variable DATEMSK to\n");
      printf("the file containing the date templates\n");
      printf("see 'man 3 getdate'\n\n");
      exit(-1);
  }

  if ( argc > 1 )
  {
      timestruct = getdate(argv[1]);
      epochtime = mktime( timestruct );
      printf("%ld\n", epochtime );
  }



}


gbratig 06-02-2007 03:46 PM

That's perfect!!! thank you very much, but really, thanks :)


All times are GMT -5. The time now is 03:17 AM.