View Full Version : Concatinate values to make date
PerlyWhite
03-30-2003, 04:45 PM
Hi,
I have a html form that has 3 selects on:
MyDay, MyMonth and MyYear
In the perl script that the form passes to, I would like the date in the format YYYY-MM-DD
So I have done the following:
$MyYear=param(MyYear);
$MyMonth=param(MyMonth);
$MyDay=param(MyDay);
$MyDate = $MyYear."-".$MyMonth."-".$MyDay;
Using this no value is inserted into the mysql database - its just left as 0000-00-00.
Any ideas where its wrong?
YUPAPA
03-30-2003, 05:55 PM
Try this:
#!/usr/bin/perl
use CGI qw(:standard :form);
use strict;
my $query = new CGI;
my $MyYear = $query->param('MyYear');
my $MyMonth =$query->param('MyMonth');
my $MyDay = $query->param('MyDay');
my $MyDate = join("-",$MyYear,$MyMonth,$MyDay);
print "Content-Type: text/plain\n\n";
print "Date: $MyDate...\n";
print "Now Add to mySQL...\n";
# You have to code this as I have no idea how the tables and stuff of your mysql db looks like.
__END__
PerlyWhite
03-30-2003, 07:41 PM
Hi,
Thanks for the reply, I tried it and it didn't work - it passed 0000-00-00 into the database.
The values are being passed correctly as I can see them in the query string.
I thought to put 3 variables together its as simple as:
$MyYear=param(MyYear);
$MyMonth=param(MyMonth);
$MyDay=param(MyDay);
$MyDate = $MyYear."-".$MyMonth."-".$MyDay;
Is it more tricker than this?
Has anyone passed a date in from a form to a perl script before to be put into a mysql table?
Ta
ian17
03-31-2003, 06:52 PM
Could you post up the query string that you saw? It might reveal something.
I've constructed dates and written them to MySql DATE data types, but I used
$MyDate = "$MyYear-$MyMonth-$MyDay";
I don't think this is a significantly different way of joining up the three numbers. There's always more than one way to do it in Perl.
Ian B.
PerlyWhite
03-31-2003, 07:17 PM
All sorted now :)
Thanks for the help.
The join worked - it was the fact that I did not have quotes around $MyDate in the insert statement!
Silly me!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.