Jump to content

Identify a month from a date


jeff5656

Recommended Posts

I have a date field and I want to do this query:

 

$query = "SELECT * FROM staffsched WHERE service = '$service' ORDER BY calldate ";

 

But how do I only select records that match a certain month?

For example if a record has calldate of 2009-10-10 It would be selected if I only wanted records from october.

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/178616-identify-a-month-from-a-date/
Share on other sites

$month=10;
$query = "SELECT * FROM staffsched WHERE service = '$service' AND MONTH(calldate)=$month ORDER BY calldate ";

However, you probably want a specific year as well;

$month=10;
$year=2009;
$query = "SELECT * FROM staffsched WHERE service = '$service' AND MONTH(calldate)=$month AND YEAR(calldate)=$year ORDER BY calldate ";

 

Chris

$month=10;
$query = "SELECT * FROM staffsched WHERE service = '$service' AND MONTH(calldate)=$month ORDER BY calldate ";

However, you probably want a specific year as well;

$month=10;
$year=2009;
$query = "SELECT * FROM staffsched WHERE service = '$service' AND MONTH(calldate)=$month AND YEAR(calldate)=$year ORDER BY calldate ";

 

Chris

 

in the case of both year and month:

$query = "select * from staffsched where service='$service' AND LEFT(calldate,7)=$year_month ORDER BY calldate;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.