Jump to content

How to get a period that includes today's date?


ivytony

Recommended Posts

Say, I want to get the period range for this week or this month and today is Saturday, Mar 08, 2008. The output of the period needs to be in timestamp format:

 

$daystart = mktime (0, 0, 0, $start_month, $start_day, $start_year); //get timestamp for the start of the range

 

$dayend= mktime (0, 0, 0, $end_month, $end_day, $end_year); //get timestamp for the end of the range

 

This range (start & end date) will be used for a mysql query that retrieves transactions that were completed in the selected range. The time of the transaction in database is in unix timestamp format, e.g. 1203557592 (if converted to readable date, this is February 20 2008 05:33:12 PM)

 

I appreciate your help!! ;)

Link to comment
Share on other sites

<?php

$todayStart = mktime(0,0,0,date('m'),date('d'),date('y'));
$todayEnd = mktime(23,59,59,date('m'),date('d'),date('y'));

echo 'Start of today was at '. date('h:i:s',$todayStart);
echo '<br>';
echo 'End of today was at '. date('h:i:s';, $todayEnd);

?>

 

Take a look at the manual, you can build these time strings any way you want. Using a combo of date() & mktime(). You can generate a timestamp for any period you want.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.