Advertisement

03.13.2001 at 06:58AM PST, ID: 20090888
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

convert date into unix timestamp
Tags: timestamp, date, unix, convert
Hi,

i would like to convert a date format into unix timestamp.
I searched the whole web but did not find anythin yet.
Any sollutions??


tnahx a lot
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: kalosi
Solution Provided By: bpouydog
Participating Experts: 4
Solution Grade: A
Views: 1011
Translate:
Loading Advertisement...
03.13.2001 at 07:18AM PST, ID: 5924812

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.13.2001 at 02:32PM PST, ID: 5926251

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.14.2001 at 08:21AM PST, ID: 5928704

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.15.2001 at 08:02AM PST, ID: 5932197

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.19.2001 at 08:45PM PST, ID: 5942379

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.29.2002 at 06:49PM PST, ID: 6906335

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.13.2001 at 07:18AM PST, ID: 5924812

Rank: Wizard

kalosi,

"..i would like to convert a date format into unix timestamp..."

What is the source of the date format???

Can you post a sample of the date format you have and the output that you want ???

Please explain with more detail your exact requirements.

Also post any sample code that you have already created.

This will help you get a more accurate answer, faster.
 
03.13.2001 at 02:32PM PST, ID: 5926251

Rank: Genius

What date format, and what timestamp format?
Have you tried using Date::Manip ?
 
03.14.2001 at 08:21AM PST, ID: 5928704
For conversion of a date format into UNIX timestamp in your Perl program, you can use the mktime() function. However, you must include "use POSIX;" at the top of your script.

  Many of the parameters that mktime takes are relative(e.g. month is zero relative, year is 1900 relative) and so I would advise you to check out the unix man page for mktime. Attaching info from the man page for mktime too for your reference.  

  The Perl code snippet I used to test it out is appended below..


#!/usr/local/bin/perl
use POSIX;

#replace the parameters with your own values..
$sec = 1;
$min = 0;
$hour = 0;
$mday = 14;
$mon = 3 - 1;
$year = 2001 - 1900;
$wday = 3;
$timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,$wday,0,-1);
print ($timestamp);
print("\n");

# just to get the current timestamp.
print(time());

###########################

NAME
     mktime - converts a tm structure to a calendar time

SYNOPSIS
     #include <time.h>

     time_t mktime(struct tm *timeptr);

DESCRIPTION
     The mktime() function converts the time represented  by  the
     tm  structure  pointed  to  by  timeptr into a calendar time
     (the number of seconds since 00:00:00 UTC, January 1, 1970).

     The tm structure contains the following members:

      int  tm_sec;     /* seconds after the minute [0, 61]  */
     int  tm_min;     /* minutes after the hour [0, 59] */
     int  tm_hour;    /* hour since midnight [0, 23] */
     int  tm_mday;    /* day of the month [1, 31] */
     int  tm_mon;     /* months since January [0, 11] */
     int  tm_year;    /* years since 1900 */
     int  tm_wday;    /* days since Sunday [0, 6] */
     int  tm_yday;    /* days since January 1 [0, 365] */
     int  tm_isdst;   /* flag for daylight savings time */

     In addition to computing the calendar time, mktime() normal-
     izes  the  supplied tm structure. The original values of the
     tm_wday and tm_yday components of the structure are ignored,
     and the original values of the other components are not res-
     tricted to the ranges indicated in  the  definition  of  the
     structure.  On  successful  completion,  the  values  of the
     tm_wday and tm_yday components are  set  appropriately,  and
     the  other  components  are  set  to represent the specified
     calendar time, but with their values forced to be within the
     appropriate  ranges.  The  final value of tm_mday is not set
     until tm_mon and tm_year are determined.

     The tm_year member must be for year 1901 or later.  Calendar
     times  before  20:45:52  UTC,  December  31,  1901  or after
     03:14:07 UTC,  January 19, 2038 cannot be represented. Port-
     able  applications  should  not  try  to create dates before
     00:00:00 UTC, January 1, 1970 or after 00:00:00 UTC, January
     1, 2038.

     The original values of the components may be either  greater
     than  or  less  than  the  specified  range.  For example, a
     tm_hour of -1 means 1 hour before  midnight,  tm_mday  of  0
     means  the day preceding the current month, and tm_mon of -2
     means 2 months before January of tm_year.

     If tm_isdst is positive, the original values are assumed  to
     be  in  the  alternate  timezone.  If  it turns out that the



SunOS 5.7           Last change: 17 Sep 1997                    1






C Library Functions                                    mktime(3C)



     alternate timezone is not valid for  the  computed  calendar
     time, then the components are adjusted to the main timezone.
     Likewise, if tm_isdst  is  zero,  the  original  values  are
     assumed  to be in the main timezone and are converted to the
     alternate timezone if the main timezone  is  not  valid.  If
     tm_isdst is negative, mktime() attempts to determine whether
     the alternate timezone is in effect for the specified time.

     Local timezone information is used as if mktime() had called
     tzset(). See ctime(3C).

RETURN VALUES
     The mktime() function returns the specified  calendar  time.
     If  the  calendar  time  cannot be represented, the function
     returns the value (time_t)-1.

USAGE
     The  mktime() function is MT-Safe in multithreaded  applica-
     tions, as long as no user-defined function directly modifies
     one of the following variables: timezone, altzone, daylight,
     and tzname. See ctime(3C).

EXAMPLES
     Example 1: Sample code using mktime().

     What day of the week is July 4, 2001?

     #include <stdio.h>
     #include <time.h>
     static char *const wday[] = {
             "Sunday", "Monday", "Tuesday", "Wednesday",
             "Thursday", "Friday", "Saturday", "-unknown-"
     };
     struct tm time_str;
     /*...*/
     time_str.tm_year    = 2001 - 1900;
     time_str.tm_mon = 7 - 1;
     time_str.tm_mday = 4;
     time_str.tm_hour = 0;
     time_str.tm_min = 0;
     time_str.tm_sec = 1;
     time_str.tm_isdst = -1;
     if (mktime(&time_str)== -1)
             time_str.tm_wday=7;
     printf("%s\n", wday[time_str.tm_wday]);


Accepted Solution
 
03.15.2001 at 08:02AM PST, ID: 5932197
Hi, your problem is simple.
And the complete solution to it is provided here,
with source code in perl and shell script to run it.


The code is:

  a) vastly documented, for your ease of understanding.

  b) thoroughly tested in Solaris 5.7, should run on any unix m/c

How to Info:
~~~~~~~~~~~~
   How to run the scripts:
       
         There are two attachments:  
                                RunScript.sh
                                &
                                DateToTimestamp.pl
 
         KEEP BOTH OF THEM IN THE SAME DIRECTORY

         The first attachment "RunScript.sh" is a shell script.
         It executes the "date" command
         (which has your date format)
         and
         passes its output to DateToTimestamp.pl.  
         (which generates the Unix timestamp and prints it)

         change its mode to executable
           (by the command):
                             $ chmod 755 RunScript.sh

         Then just run this script
           (by the command):
                             $ RunScript.sh

And you get what you want.

REFERENCES
~~~~~~~~~~
  1. Manuals
    $ man  date  (for the manual on unix date format)
    $ man  mktime (for the manual on mktime method I used in .pl)

  2. The POSIX library.
 
##############################################

DateToTimestamp.pl



#!/usr/local/bin/perl

#
# author:  nabarun of www.arzoo.com
#

use POSIX;

my (
    $wday,
    $year,
    $month,
    $date,
    $time,
    $zone,
    @wdays,
    @months,
);

#
# Days in a week, as appears in the output of unix shell command "date"
#
@wdays = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

#
# Months in a year, as appears in the output of unix shell command "date"
#
@months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");


#
# the date commands output is passed as the input here (by the RunScript.sh)
#
$inputDate = <STDIN>;

#
# storing the different words in the output
#
@words = split (/\s+/, $inputDate);


$wday  = $words[0];
$month = $words[1];
$date  = $words[2];
$time  = $words[3];
$zone  = $words[4];
$year  = $words[5];

print "\ndate commands output:\n"
      . "~~~~~~~~~~~~~~~~~~~~~\n\t\t$inputDate\n";


for($i = 0; $i <= $#wdays; $i++) {
  if ("$wday" eq "$wdays[$i]") {
    $wday = $i;
#   print "$wday = $wdays[$i]\n";
    last;
  }
}

for($i = 0; $i <= $#months; $i++) {
  if ("$month" eq "$months[$i]") {
    $month = $i;
#   print "$month = $months[$i]\n";
    last;
  }
}

@time_components = split (/\:/, $time);
$hour  = $time_components[0];
$min  = $time_components[1];
$sec  = $time_components[2];
$year = $year - 1900;

print "arguments to the mktime() method:\n"
  .   "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n";
print "sec = $sec, min = $min, hour = $hour,\ndate = $date, month = $month, "
  . "year (this yr. - 1900) = $year, day = $wday \n\n";


$timestamp = mktime($sec, $min, $hour, $date, $month, $year, $wday, 0, -1);

print "********************************\n";
print "CALCULATED TIMESTAMP = ";
print "$timestamp \n";
print "********************************\n";

print "PRESENT TIMESTAMP    = ";
print (time());
print "\n";
print "********************************\n\n";


##################################

RunScript.sh


#!/bin/sh

#
# @ nabarun of www.arzoo.com
#

#
# clear the screen
#
clear;


#
# run the unix command date and pass its input to the output of
# the perl script  DateToTimeStamp.pl.
#
date | perl DateToTimestamp.pl;




 
03.19.2001 at 08:45PM PST, ID: 5942379

Rank: Wizard

kalosi,

Did you get the solution you were looking for??

What solution, if any, did you use??

Pl. let us know.

NOTE: if you have found a solution on your own or if this question has become obsolete,  please delete
it and free up your points.
 
03.29.2002 at 06:49PM PST, ID: 6906335
Per recommendation, force-accepted by
Netminder
CS Moderator
 
 
20080236-EE-VQP-29