I am tying to convert a date to put into a database from a string (ie:
January, February) to a numeric value (ie: 01,02). I am taking the
value from a form, which is a drop down menu listing the months.
$sMonth1 = $_POST['Smonth']; returns the money selected from the form.
When I go to format the month from a string to numeric with
date('m',strtotime($sMonth1));
it returns 12, no matter which month I select.
In reading the docs at php.net, date('m',strtotime($sMonth1)); is
correct to reformat from a string to a time format.
What am I missing.
mark bomgardner
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Date Conversion
am 16.05.2006 21:44:54 von Brad Bonkoski
Mark Bomgardner wrote:
> PHP 4.4/MySQL 4.0
>
> I am tying to convert a date to put into a database from a string (ie:
> January, February) to a numeric value (ie: 01,02). I am taking the
> value from a form, which is a drop down menu listing the months.
>
> $sMonth1 = $_POST['Smonth']; returns the money selected from the form.
> When I go to format the month from a string to numeric with
> date('m',strtotime($sMonth1));
> it returns 12, no matter which month I select.
>
> In reading the docs at php.net, date('m',strtotime($sMonth1)); is
> correct to reformat from a string to a time format.
>
> What am I missing.
>
>
> mark bomgardner
>
An idea along a different path would be....
for your original select box where you pick the month do something like
this:
.....
Then the value passed to your form will be the numeric representation of
the month so there will be no need to translate the String --> number..
HTH
-Brad
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Date Conversion
am 16.05.2006 22:29:23 von Ralph Brickley
A simple associate array would work as well, although not quite as elegent.
$months_arr = array("January"=>01, "February"=>02...);
-----Original Message-----
From: Mark Bomgardner [mailto:mbomgardner@kletc.org]
Sent: Tuesday, May 16, 2006 12:35 PM
To: Php-Db
Subject: [PHP-DB] Date Conversion
PHP 4.4/MySQL 4.0
I am tying to convert a date to put into a database from a string (ie:
January, February) to a numeric value (ie: 01,02). I am taking the
value from a form, which is a drop down menu listing the months.
$sMonth1 = $_POST['Smonth']; returns the money selected from the form.
When I go to format the month from a string to numeric with
date('m',strtotime($sMonth1));
it returns 12, no matter which month I select.
In reading the docs at php.net, date('m',strtotime($sMonth1)); is
correct to reformat from a string to a time format.
What am I missing.
mark bomgardner
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Date Conversion
am 16.05.2006 22:46:47 von Ralph Brickley
ADDENDUM:
To Convert your date string, use the associate array:
$months_arr = array("January"=>01, "February
=>02...);
$month = $months_arr["February"];
* Replace $months_arr["February"] with $_POST["Month"];
// Output
$month = 01;
Ralph Brickley
-----Original Message-----
From: Ralph Brickley [mailto:ralphbrickley@verizon.net]
Sent: Tuesday, May 16, 2006 1:29 PM
To: mbomgardner@kletc.org; 'Php-Db'
Subject: RE: [PHP-DB] Date Conversion
A simple associate array would work as well, although not quite as elegent.
$months_arr = array("January"=>01, "February"=>02...);
-----Original Message-----
From: Mark Bomgardner [mailto:mbomgardner@kletc.org]
Sent: Tuesday, May 16, 2006 12:35 PM
To: Php-Db
Subject: [PHP-DB] Date Conversion
PHP 4.4/MySQL 4.0
I am tying to convert a date to put into a database from a string (ie:
January, February) to a numeric value (ie: 01,02). I am taking the
value from a form, which is a drop down menu listing the months.
$sMonth1 = $_POST['Smonth']; returns the money selected from the form.
When I go to format the month from a string to numeric with
date('m',strtotime($sMonth1));
it returns 12, no matter which month I select.
In reading the docs at php.net, date('m',strtotime($sMonth1)); is
correct to reformat from a string to a time format.
What am I missing.
mark bomgardner
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php