Hi everyone!
Can anybody give some tips, advices or ideas of how to calculate the days over a month.
I have a login system and a database but I don't want it to be specific with dates. the idea is having expressions like :
OVER A MONTH, OVER A WEEK, WITHING A MONTH etc.
I will truly appreciate it.
Calculate date (over a month)
Moderator: General Moderators
Re: Calculate date (over a month)
Days over a month could be 29 -> infinity. Could we get some more details?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Calculate date (over a month)
Yeah it worked ok with two weeks but It gets confusing when doing it a month since every month doesn't have exact amount of days (28,29,30,31)
I got this for within 2 weeks
I got this for within 2 weeks
Code: Select all
$day = '3'; //sample
$w_ago = strtotime("-7 day");
$week_ago = date("d", $w_ago);
$two_w_ago = strtotime("-14 day");
$two_week_ago = date("d", $two_w_ago);
if($day < $week_ago && $day >= $two_week_ago){
echo '<strong>LAST LOGIN: </strong>'.'whitin 2 weeks';
}
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: Calculate date (over a month)
I think your underlying logic is flawed. What your code says, to put it into plain English is:
I if you wanted to check if the user last logged in during the week before last, then add $last_login_time < strtotime('1 week ago').
- Give me the day of the month 1 week ago
- Give me the day of the month 2 weeks ago
- Tell me if the day of the month when the user last logged in is between the day of the month 2 weeks ago and the day of the month last week
Code: Select all
<?php
$last_login_time = strtotime('15 days ago'); // for example... presumably this actually comes from the database
if ($last_login_time > strtotime('2 weeks ago')) {
echo '<strong>LAST LOGIN: </strong> within 2 weeks';
}
Last edited by pickle on Fri Jun 08, 2012 9:42 am, edited 1 time in total.
Reason: Fixed broken list tag
Reason: Fixed broken list tag