THE ZEPINT NETWORK

programmer assist

PHP PHP XML Feeds

PHP Questions PHP Solutions PHP Articles

PHP is a popular open-source programming language used primarily for developing server-side applications and dynamic web content, and more recently, other software. The name is a recursive acronym for "PHP: Hypertext Preprocessor".

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 value

answer 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

Re: Getting a mysql datetime field value

reply by Bejaan

Thank you, my partner just tried this one, he says its okay now.

Post reply Subscriptions

Got a PHP Question?

Just Sign Up and ask the top PHP experts!

Search via Google

User Login

Email Address

Password

PHP Experts

Rank Expert Points
#1 Srirangan 2650
#2 Anurag 600
#3 mastercomputers 100
This a list of the Top PHP experts, how many points do you have?

Leading Experts

Rank Expert Points
#1 frankzzsword 4600
#2 Bejaan 2900
#3 csfreak 1100
#4 Anurag 700
#5 keyvez 700
#6 nnarasimha 600
#7 Nakata 600
#8 martinig 600
#9 mastercomputers 400
#10 Huntress 150
#11 Adkron 150
#12 Yogesh 100
#13 lexxwern 100
#14 Mustan Khan 100
#15 poizn 100
This is a list of overall best performing experts, how many points do you have?