For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > November 2006 > Convert Date to Timestamp.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Convert Date to Timestamp.
Sara

2006-11-01, 3:55 am

I am getting Month, Day and Year from Drop Downs of a form to convert given values to Unix timestamp.
I am able to put values in all the variables below except for $wday & $yday. Any ideas as how I can get those with limited user input of month, day and year only?

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

$sec = 1;
$min = 0;
$hour = 0;
$mday = 01;
$mon = 10;
$year = 107;
$wday = ?;
$yday = ?;
$timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,-1);
print ($timestamp);

Charles K. Clarkson

2006-11-01, 6:55 pm

Sara <mailto:sara.samsara@gmail.com> wrote:

: I am getting Month, Day and Year from Drop Downs of a form to
: convert given values to Unix timestamp.
: I am able to put values in all the variables below except for
: $wday & $yday. Any ideas as how I can get those with limited
: user input of month, day and year only?

Use timegm() from the Time::Local module.

HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

http://www.clarksonenergyhomes.com/

Don't tread on my bandwidth. Trim your posts.

David Romero

2006-11-01, 6:55 pm

See the Date::Parse Module from cpan



On 10/31/06, Sara <sara.samsara@gmail.com> wrote:
> I am getting Month, Day and Year from Drop Downs of a form to convert given values to Unix timestamp.
> I am able to put values in all the variables below except for $wday & $yday. Any ideas as how I can get those with limited user input of month, day and year only?
>
> #!/usr/local/bin/perl
> use POSIX;
>
> $sec = 1;
> $min = 0;
> $hour = 0;
> $mday = 01;
> $mon = 10;
> $year = 107;
> $wday = ?;
> $yday = ?;
> $timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,-1);
> print ($timestamp);
>
>



--
David Romero
##################################
http://www.iluminawebs.com
Mumia W.

2006-11-01, 6:55 pm

On 11/01/2006 12:04 AM, Sara wrote:
> I am getting Month, Day and Year from Drop Downs of a form to convert given values to Unix timestamp.
> I am able to put values in all the variables below except for $wday & $yday. Any ideas as how I can get those with limited user input of month, day and year only?
>
> #!/usr/local/bin/perl
> use POSIX;
>
> $sec = 1;
> $min = 0;
> $hour = 0;
> $mday = 01;
> $mon = 10;
> $year = 107;
> $wday = ?;
> $yday = ?;
> $timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,-1);
> print ($timestamp);
>


Is this what you're looking to do?

use POSIX qw(mktime ctime);
my @ary = (0) x 9;
@ary[3,4,5] = (1,10,107);

{
local $\ = "\n";
my $tstamp = mktime(@ary);
print $tstamp;
print ctime($tstamp);
}



John W. Krahn

2006-11-03, 7:55 am

Sara wrote:
> I am getting Month, Day and Year from Drop Downs of a form to convert given
> values to Unix timestamp. I am able to put values in all the variables
> below except for $wday & $yday. Any ideas as how I can get those with
> limited user input of month, day and year only?
>
> #!/usr/local/bin/perl
> use POSIX;
>
> $sec = 1;
> $min = 0;
> $hour = 0;
> $mday = 01;
> $mon = 10;
> $year = 107;
> $wday = ?;
> $yday = ?;
> $timestamp = mktime($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,-1);
> print ($timestamp);


The only values that you have to supply to POSIX::mktime() are the first six,
the other values are recomputed, so:

my ( $sec, $min, $hour, $mday, $mon, $year ) = ( 1, 0, 0, 1, 10, 107 );

my $timestamp = mktime( $sec, $min, $hour, $mday, $mon, $year );



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com