| |||||||
This is a discussion on Need ideas. within the Technical Help forums, part of the Off Topic category; I am building a site for work and need some ideas. Managers want period reviews to be done for them ...
![]() |
| | Thread Tools |
| | #1 |
| iPod 30gb Join Date: Aug 2009 Location: Widnes
Posts: 1,090
![]() | Need ideas.I am building a site for work and need some ideas. Managers want period reviews to be done for them i.e content is filled in automatically. Luckily each period starts after 28 days regardless of weather there is a national holiday (i.e easter) or not So I have a script that calculates each period What I need to figure out is when you submit a sale you made on 08-04-2011 it knows it's period 1 and if you submit on 03-06-2011 it knows its period 2 so far all I have it generating is Period: 1 starts 07-04-2011 Period: 2 starts 02-06-2011 Period: 3 starts 30-06-2011 Period: 4 starts 28-07-2011 Period: 5 starts 25-08-2011 Period: 6 starts 22-09-2011 Period: 7 starts 20-10-2011 Period: 8 starts 17-11-2011 Period: 9 starts 15-12-2011 Period: 10 starts 12-01-2012 Period: 11 starts 09-02-2012 Period: 12 starts 08-03-2012 Period: 13 starts 05-04-2012 So I need to figure out a way of telling my system that if a user submits a sale on the 9th of April, it is in period 1, but if they submit a sale on 9th of June it's in period 2 and wont count towards period one. Any ideas?
__________________ Totally Free iPad | McFlurry Ice Cream Van Everything I say reflects my own opinions and not that of any company. |
|
| | #2 |
| What to put... | I may be talking stupid so ignore me if i am but cant you a 'if tag' then if so then it 'posts' to the section you want?
__________________ |
|
| | #3 |
| iPod 30gb Join Date: Aug 2009 Location: Widnes
Posts: 1,090
![]() | Yeah I am thinking IF but I am not sure how to say if the date is less than that specified date. I should mention its in PHP. I can get today's date. I can get the date of the next period. I need to check if today is before, equal to or greater than the date of each period - not sure how to do that though.
__________________ Totally Free iPad | McFlurry Ice Cream Van Everything I say reflects my own opinions and not that of any company. |
|
| | #4 |
| What to put... |
__________________ |
|
| | #5 |
| iPod 30gb Join Date: Aug 2009 Location: Widnes
Posts: 1,090
![]() | I tried that. But if I go to the previous month i.e 30th March. PHP only reads the "30" from "30/03/2011". So if I ask you which is less (or earlier) 30th march or 4 April you would say 30th march. PHP compares it as: IS 30 < 4 Which it isn't.
__________________ Totally Free iPad | McFlurry Ice Cream Van Everything I say reflects my own opinions and not that of any company. |
|
| | #6 |
| What to put... | Is there are way to combine multiple if tags at once like you can in css?
__________________ |
|
| | #7 |
| Free The Gadgets | If period 1 starts on 07-04-2011 and say for example a sale is made on 20-08-2011. Then you would need to calculate how many days between these two dates. Found this code on the internet, it looks like it does the job. You'll obviously have to add in any select statements to assign the dates to the variables. <?PHP $result=""; $second=1; $minute=$second*60; $hour=$minute*60; $day=$hour*24; $week=$day*7; #change the data as you want to be calculated $date1=01/01/01; $date2=01/02/03; $timestamp1 = strtotime($date1); $timestamp2 = strtotime($date2); $diffrence = $timestamp2-$timestamp1; $weeks=round((((($diffrence/$minute)/$hour)/$day)/$week)); $r_days=$diffrence-($weeks*$week*$day*$hour*$minute*$second); $days=round(((($r_days/$minute)/$hour)/$day)); $r_hours=$r_days-($days*$day*$hour*$minute*$second); $hours=round((($r_hours/$minute)/$hour)); $r_minutes=$r_hours-($hours*$hour*$minute*$second); $minutes=round($r_minutes/$minute); $seconds=$r_minutes-($minutes*$minute*$second); $result="it has been $weeks weeks, $days days, $hours $hours, $minutes minutes and $seconds seconds since $date1"; ?> Once you have the number of days between dates, take that number and add 28 to it, then divide it by 28. Without the decimal points that will give you period number. Hope that makes some kind of sense? That's how I would go about it anyway!
__________________ |
|
| | #8 | ||
| Mini Mac | Quote:
Quote:
Code: $result = "it has been " . $weeks . " weeks, " . $days . " days, " . $hours . " hours, " . $minutes . " minutes and " . $seconds . " seconds since " . $date1; $date would equal the current date and I would create a variable for each of the periods as it will make it extremely easier to maintain. Code: if ($date > $period13)
{
}
else if ($date > $period12)
{
}
.......
else if ($date > $period1)
{
}
Last edited by chapperzUK; 08-04-11 at 01:20 AM.. | ||
|
| | #9 | |
| Free The Gadgets | Quote:
The way I done it will work indefinitely and once coded won't have to be touched again. Unless of course there are only 13 periods in total!
__________________ Last edited by corky20; 08-04-11 at 01:41 AM.. | |
|
| | #10 | |
| Mini Mac | Quote:
| |
|
| | #11 |
| Free The Gadgets | You actually have me thinking twice... if it is only the 13 periods then an IF statement would be better. I'm not sure now lol, not clear from the first post if it's only the 13 periods or not!
__________________ |
|
| | #12 |
| What to put... | Call me silly but can't you just do it on a 365 day basis and calculate the day of each date. I mean you would have to re-code it for a leap year but that wouldn't take 2 seconds and they don't come too often.
__________________ |
|
| | #13 |
| iPod 30gb Join Date: Aug 2009 Location: Widnes
Posts: 1,090
![]() | There are 13 periods in a year and exactly 28 days in each period regardless of holidays and it will change per year, because each year starts at a different time. Corky you are right in saying that the periods don't stop but I can't get your code to output data for me. What I was given was this (from another forum) Code: $date = date_create(date('Y-m-d'));
//Periods
$period1_start = date_create('2011-04-08');
$period2_start = date_create('2011-06-03');
$period3_start = date_create('2011-07-01');
if ($period1_start <= $date && $date < $period2_start) {
$p = "p1";
}
if($period2_start <= $date && $date < $period3_start){
$p = "p2";
}
if($period3_start <= $date){
$p = "p3";
}
//Weekly
$week1_start = date_create('2011-04-03');
$week2_start = date_create('2011-04-10');
$week3_start = date_create('2011-04-17');
if ($week1_start <= $date && $date < $week2_start) {
echo "Week is week one";
}
if($period2_start <= $date && $date < $period3_start){
$p = "p2";
}
if($period3_start <= $date){
$p = "p3";
}
__________________ Totally Free iPad | McFlurry Ice Cream Van Everything I say reflects my own opinions and not that of any company. |
|
![]() |
| Thread Tools | |
| |