Jump to content

how to get the month in the date in set of records


phpmady

Recommended Posts

Hi,

 

I am having set of records,

id     

name

dob

 

1  philip        1278226800

2  winsent    1278216800

3  Benn          1272226800

 

 

now i want to fetch the records based on the month and listing out, can anyone help me to write for the above concept.

 

Thanks,

 

 

Can you clarify that a little? Do you mean you want to list all the records, grouped or ordered by the month, or you want to list the records that are from a particular month?

Can you clarify that a little? Do you mean you want to list all the records, grouped or ordered by the month, or you want to list the records that are from a particular month?

 

 

Hi,

 

First of all Thanks for your reply, i want to list the records that are from a particular month

 

thanks,

Use the msyql MONTH() function directly in your query. You will need to get the Unix Timestamp into a usable DATE format (why do people still bother to use a Unix Timestamp.) See the mysql FROM_UNIXTIME() function to do that.

 

Untested but should work -

 

$month = 9; // the month you want to find

$query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = $month";

 

If you want the current month, you could do that directly in the query -

 

$query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = MONTH(CURDATE())";

I don't store UNIX timestamps, so I haven't tested this, but it should work, as far as I can tell.

 

$month = 5; // query is set up for numeric month representation . . .
$query = "SELECT `field_1`, `field_2` FROM `table` WHERE FROM_UNIXTIME(`timestamp_field`, '%m') = $month";

 

Use the msyql MONTH() function directly in your query. You will need to get the Unix Timestamp into a usable DATE format (why do people still bother to use a Unix Timestamp.) See the mysql FROM_UNIXTIME() function to do that.

 

Untested but should work -

 

$month = 9; // the month you want to find

$query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = $month";

 

If you want the current month, you could do that directly in the query -

 

$query = "SELECT * FROM your_table WHERE MONTH(FROM_UNIXTIME(your_Unix_Timestamp_column)) = MONTH(CURDATE())";

 

Thanks,

 

Thanks i have made it using your query, and thanks for make me knowledgable in date functions.

 

Thanks

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.