Forum Moderators: coopster
while($row = mysql_fetch_array($ms_query)) {
$user_bday = $row['birthdate'];
}
$user_month = date(m, $user_bday);
$user_day = date(d, $user_bday);
$user_year = date(Y, $user_bday);
This is what was on php.net:
GUGU_Brasil
19-Jun-2003 03:21
USE THIS IF U HAVE PROBLEM WHEN FORMATING DATE. IF YOUR SERVER IS WINDOWS, THE PHP WILL UNDERSTAND THE DATE FUNCTION OK. BUT IF YOUR SYSTEM WILL RUN ON A UNIX PLATAFORM, U HAVE TO TRANSLATE A STRING TO DATE SO THAT THE UNIX CAN UNDERSTAND THE DATETIME AS DATE.0.PROBLEM: ECHOS WRONG DATE. (Ususally: 1969-02-12);
1.SOLVER:
//on RecordSets, lives the DateTime Field From your Database Table
$DATE_STR = $RECORD_SET->FIELD["DATE_TIME_FIELD"];
//use strtotime(); function to tell Server that this STR is a DATE. WORKS for UNIX SERVER.
$DATE = strtotime($DATE_STR);
//use date(); Then The Server Will Understand the DATE as DATE and format it as U desire.
$STR_OF_DATE = date("d-m-Y h:i:s",$DATE);
//I hope this could help,
//GUGU_BRASIL.
I tried this and it displayed today's date. I am not sure if I did something wrong?
-FM-
First I specify in my sql query how I would like the date formatted.
$sql = "select name, date_format(birthdate,'%d/%m/%y') as fbday from users"
..and then I use explode to get the date parts..
$dateparts = explode( $row['fbday'] );
Alternatively you could just specify the date field three times in your query...
$sql = "select name, dayofmonth(birthdate) as b_day, month(birthdate) as b_month, year(birthdate) as b_year from users"
.. and you'll get it already broken into day month and year fields for you.
Also, I have never used the exlode () function so I don't know much about it.
If thier is no other way to get the desired results, then I guess am I going to have to format when I pull the info.. argh.
thanks for your help,
-FM-
Okay - so you pulled it out and exploded it.
So now you can print it as...
print $dateparts[0].'/'.$dateparts[1].'/'.$dateparts[2];
..or if you need to create a timestamp string from it then use strtotime as GUGU_Brasil suggested..
$birthday = strtotime( $dateparts[2].'-'.$dateparts[1].'-'.$dateparts[0] );
since it is a DATE 0000-00-00 by default, I just assigned what I pulled from the db to a var:
include("db_fns.php");
$m_query = "SELECT * FROM members WHERE name = '$valid_user'";
$ms_query = mysql_query($m_query) or die (mysql_errno().": ".mysql_error()."<BR>");
while($row = mysql_fetch_array($ms_query)) {
$user_bday = $row['birthdate'];
};
$disp_bday = explode("-", $user_bday);
$user_month = $disp_bday[1];
$user_day = $disp_bday[2];
$user_year = $disp_bday[0]
This displays from db exactly what I need and does a flawless job. Thanks for trying to help Graham, the explode() is what did it.
-FM-