Getting a mysql datetime field value
DiggBlinkRedditDeliciousTechnorati
question by Bejaan | Moderate
Hi,
I have a table which looks like:
username | reg_date -----------------------------------
TEXT | DATETIME
I'd like to get all users who registered in a certain month:
SELECT * FROM my_table WHERE YEAR(reg_date)=2006 AND MONTH(reg_date)=3;
Now I should get the value of reg_date in my result set, I'm wondering how can I then extract individual components of the date at that point? For instance I'd like to know what day the record was registered on. Right now I have something like:
$result = mysql_query("stmt");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$strUserName = $row['username'];
$reg_day = $row['DAY('reg_date') ']; // ??????????????
}
So yeah I just want to get individual components of the date.
Thanks
Post reply
Subscriptions
Re: Getting a mysql datetime field valueanswer by Srirangan Do something like this:
SELECT *, DAY(reg_date) as reg_day FROM my_table WHERE YEAR(reg_date)=2006 AND MONTH(reg_date)=3;
Then access the day in the results with $row['reg_day']
Hope that helps!
Post reply
Subscriptions
Got a PHP Question?
Just Sign Up and ask the top PHP experts!
|