FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Spliting Date

 


DanielXP
Ok a date saves into a db and i want to split it.

this is how it goes into the db

DD/MM/YYYY

and i want it to split so like

$DD = "DD";
$MM = "MM";
$YYYY = "YYYY";

eg today

21/08/2006

$DD ="21";
$MM = "08";
$YYYY = "2006";

Is there any way of doing this?

Thanks!
ganbate
DanielXP wrote:
Ok a date saves into a db and i want to split it.

this is how it goes into the db

DD/MM/YYYY

and i want it to split so like

$DD = "DD";
$MM = "MM";
$YYYY = "YYYY";

eg today

21/08/2006

$DD ="21";
$MM = "08";
$YYYY = "2006";

Is there any way of doing this?

Thanks!


use explode function.

example :
Code:

$today = "21/08/2006"

$date = explode("/", $today);

$DD = $date[0];
$MM = $date[1];
$YYYY = $date[2];
DanielXP
Parse error: parse error, unexpected T_VARIABLE

on line

$date = explode("/", $today);

EDIT: Fixed thanks mate!
hexkid
I'd do it a bit different than ganbate

SQL
Code:
select year(date_column), month(date_column), day(date_column) from ...


PHP
Code:
$DD = $dbvalue[2];
$MM = $dbvalue[1];
$YYYY = $dbvalue[0];
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.