Page 1 of 1

first and last day

Posted: Sun Apr 04, 2004 7:59 am
by pelegk2
i need to get the first day from midnight
and last day until almost midnight
for a query i do where i want to check that the date is in the current month!
and the timme in the db is hold as unix_time!
thanks inadvane
peleg

Posted: Sun Apr 04, 2004 9:08 am
by litebearer
Admin Edit: Added tags around code.[/color]

Code: Select all

<?PHP

// get current month and year

$month1 = date(“F”);
$year1 = date(“y”);

// get month and date of stored timestamp

$month2 = date(“F”, whatever_the_timestamp_value_is);
$year2 = date(“y”, whatever_the_timestamp_value_is);


// compare 

$test1 = $month1.$year1;
$test2 = $month2.$year2;

if($test1 == $test2){ 
do this 
} else { 
do this instead. 
} 

?>

Lite...

Posted: Tue Apr 06, 2004 9:55 am
by pelegk2
what?this want what i asked for!
for example : now is april month
i want to know what the first time/date of the month , and what is the last!
beacuse i need to do a comae in a query :
$startMonth<=currentmonth<=$endofmonth

Posted: Tue Apr 06, 2004 8:43 pm
by litebearer
"i need to get the first day from midnight
and last day until almost midnight
for a query i do where i want to check that the date is in the current month!
and the timme in the db is hold as unix_time!
thanks inadvane
peleg"

from the above statement we can determine the following constants:

$start_day = 01
$start_hour = 12 AM
$start_minute = 00
$start_second = 01

If the current month = 1, 3, 5, 7, 8, 10 or 12 then
$end_day = 31
Else If current month = 4,6,9 or 11 then
$end_day = 30
Else If current year is a leap year then
$end_day = 29
Else
$end_day = 28

$end_hour = 11PM
$end_minute = 59
$end_second = 59

Using the above contants with the current month we can utilize the mktime() function (http://www.php.net/mktime) to create a beginning and ending timestamp.

We can then take the timestamp from your database cam compare to the begining and ending timestamps to determine if the database date is within the current month.

OR

We can do it the easy way and simply check the month and year values to reach the same conclusion. Unless one or more of the dates is being "twisted" by Einstein's Time Space Theory, equal month and year equate to being in the same period.

Posted: Wed Apr 07, 2004 3:08 am
by twigletmac
litebearer wrote:Unless one or more of the dates is being "twisted" by Einstein's Time Space Theory, equal month and year equate to being in the same period.
lol

Mac

Posted: Wed Apr 07, 2004 10:09 am
by pickle
$curr_time = time();
$curr_month = date('m',$curr_time);
$curr_year = date('Y',$curr_time);
$number_of_days_in_month = date('t',$curr_time);

$first_day_of_current_month = mktime(0,0,0,$curr_month,1,$curr_year);
$last_day_of_current_month = mktime(23,59,59,$curr_month,$number_of_days_in_month,$curr_year);