thank you
Date
Moderator: General Moderators
-
glennalmeda
- Forum Newbie
- Posts: 14
- Joined: Mon Jan 26, 2004 9:00 pm
Date
How can i make the variables $Year (e.g. 2004), $Month (e.g. January) , and $Day (e.g. 30) stored in a single variable in a date format?
thank you
thank you
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I recently made a script that does that, it takes in a date ( yyyy-mm-dd ) and then it explodes it to $year $month $day
If you want to do the opposite, such as getting all the different variables to come together into 1 variable date (ie. year+day+month = $date ) then you would probably want to set up an array...
Code: Select all
<?php
echo "<div align="center">"
."<form action="{$_SERVER['PHP_SELF']}"\n"
."<p>Type your Date here: eg. 2004-01-31 (y-m-d)<br/>\n"
."<input type="text" name="date" cols="40"><br>\n"
."<input type="submit" name="submitdate" value="SUBMIT" /></p>\n"
."</form>\n"
$newdate = explode("-",$date);
$month = $newdate[1]; // eg. February
$day = $newdate[2]; // eg. 04
$year = $newdate[0]; // eg. 2004
echo "the current day is $day <br>\n"
."the current month is $month <br>\n"
."the current year is $year <br>\n";
?>
Last edited by John Cartwright on Fri Jan 30, 2004 1:57 am, edited 1 time in total.
-
glennalmeda
- Forum Newbie
- Posts: 14
- Joined: Mon Jan 26, 2004 9:00 pm
date
ok. here's my problem...
For example, i have a variables named Month = "January", Day = "30" and Year = "2004".
Those are user-input. I want all of them stored in a single variable for example named Birthday. So how can i combine all those variables and stored in one variable in a date format so i can use it and store in my database. Hope u get my question. thank you
For example, i have a variables named Month = "January", Day = "30" and Year = "2004".
Those are user-input. I want all of them stored in a single variable for example named Birthday. So how can i combine all those variables and stored in one variable in a date format so i can use it and store in my database. Hope u get my question. thank you
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
glennalmeda
- Forum Newbie
- Posts: 14
- Joined: Mon Jan 26, 2004 9:00 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Then you would use the implode function found here - http://ca2.php.net/manual/en/function.implode.php
That should do the trick.
Code: Select all
<?php
$array = array('year', 'month', 'day');
$date = implode("-", $array);
echo "the current date is $date\n";
?>-
glennalmeda
- Forum Newbie
- Posts: 14
- Joined: Mon Jan 26, 2004 9:00 pm
Here a sample code:
$frmDate = "$ddFrmYear-$ddFrmMonth-$ddFrmDay";
(e.g. frmDate = 2004-01-1)
$frmDate = "$ddThruYear-$ddThruMonth-$ddThruDay";
(e.g. ThruDate = 2004-02-1)
and i have sql statement like this:
$sql = "SELECT * FROM order_history, dealer_table WHERE o_num = '$txtOrder_Number' AND o_status = '$ddStatus' AND company LIKE '%$txtCompany%' AND o_date BETWEEN '$FrmDate' AND '$ThruDate'";
but i think frmDate n ThruDate is invalid when i use it in sql statement because its not converted into a date format...
$frmDate = "$ddFrmYear-$ddFrmMonth-$ddFrmDay";
(e.g. frmDate = 2004-01-1)
$frmDate = "$ddThruYear-$ddThruMonth-$ddThruDay";
(e.g. ThruDate = 2004-02-1)
and i have sql statement like this:
$sql = "SELECT * FROM order_history, dealer_table WHERE o_num = '$txtOrder_Number' AND o_status = '$ddStatus' AND company LIKE '%$txtCompany%' AND o_date BETWEEN '$FrmDate' AND '$ThruDate'";
but i think frmDate n ThruDate is invalid when i use it in sql statement because its not converted into a date format...
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
You understand you are declaring $frmDate twice, right?Here a sample code:
$frmDate = "$ddFrmYear-$ddFrmMonth-$ddFrmDay";
(e.g. frmDate = 2004-01-1)
$frmDate = "$ddThruYear-$ddThruMonth-$ddThruDay";
(e.g. ThruDate = 2004-02-1)
BTW: If you want to be using date format... make sure you are not getting it inputted like this, January, 04 2004 or something. It's gotto be yyyy-mm-dd
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
What you want to do instead of all that is do something like this
try echo'ing your arrays to see if they are getting the proper input.
eg.
Code: Select all
<php
$array_frmDate = array('ddFrmYear', 'ddFrmMonth', 'ddFrmDay');
$FrmDate = implode("-", $array_frmDate);
$array_ThruDate = array('ddThruYear', 'ddThruMonth', 'ddThruDay');
$ThruDate = implode("-", $array_ThruDate);
?>try echo'ing your arrays to see if they are getting the proper input.
eg.
Code: Select all
<?php
echo "$ThruDate";
?>