redneonrt Posted June 8, 2006 Share Posted June 8, 2006 I have php insert a timestamp for each enrty in my db table.I would like to be able to seach for all entries from a particular month say May for example.But Im not quite sure how to go about this. Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/ Share on other sites More sharing options...
poirot Posted June 8, 2006 Share Posted June 8, 2006 It depends... What is the format of the inserted timestamp? Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43398 Share on other sites More sharing options...
redneonrt Posted June 8, 2006 Author Share Posted June 8, 2006 [!--quoteo(post=381608:date=Jun 8 2006, 04:29 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 04:29 PM) [snapback]381608[/snapback][/div][div class=\'quotemain\'][!--quotec--]It depends... What is the format of the inserted timestamp?[/quote]when I insert a date, strtotimeexample $date = strtotime("06/07/2006"); Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43400 Share on other sites More sharing options...
poirot Posted June 8, 2006 Share Posted June 8, 2006 OK, that means it's using an UNIX timestamp.You can use the following query:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]table[/color] [color=green]WHERE[/color] EXTRACT(MONTH [color=green]FROM[/color] [color=orange]FROM_UNIXTIME(date))[/color] [color=orange]=[/color] month_here [!--sql2--][/div][!--sql3--]Now, I usually would use PHP to get this. But I'm following Barand so I'll use the least PHP possible. I hope it's a good thing [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43402 Share on other sites More sharing options...
redneonrt Posted June 9, 2006 Author Share Posted June 9, 2006 Im not having much luck making this work.I tried this [code]SELECT *FROM `ext`WHERE EXTRACT(MONTH FROM_UNIXTIME( date ) ) =06[/code]I get a mysql error.Could someone provide another example please? Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43697 Share on other sites More sharing options...
poirot Posted June 9, 2006 Share Posted June 9, 2006 [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]`ext`[/color] [color=green]WHERE[/color] EXTRACT(MONTH [color=green]FROM[/color] [color=orange]FROM_UNIXTIME(date))[/color] [color=orange]=[/color] 6 [!--sql2--][/div][!--sql3--]You missed a FROM... Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43702 Share on other sites More sharing options...
redneonrt Posted June 9, 2006 Author Share Posted June 9, 2006 Woops [img src=\"style_emoticons/[#EMO_DIR#]/huh.gif\" style=\"vertical-align:middle\" emoid=\":huh:\" border=\"0\" alt=\"huh.gif\" /] Thanks for your help though. Quote Link to comment https://forums.phpfreaks.com/topic/11523-newb-date-question/#findComment-43718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.