eXceem

Go Back   eXceem > Off Topic > Technical Help

Claim your amazing £1,000 slots booster bonus now!


Need ideas.

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

Reply
 
Thread Tools
Old 07-04-11, 06:27 PM   #1
iPod 30gb
 
Join Date: Aug 2009
Location: Widnes
Posts: 1,090
cono1717 is a jewel in the rough

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.
 
Reply With Quote
Old 07-04-11, 06:32 PM   #2
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
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?
__________________
 
Reply With Quote
Old 07-04-11, 06:36 PM   #3
iPod 30gb
 
Join Date: Aug 2009
Location: Widnes
Posts: 1,090
cono1717 is a jewel in the rough
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.
 
Reply With Quote
Old 07-04-11, 06:42 PM   #4
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
Does this help?

PHP Tutorials: Less Than or Equal To, Greater Than or Equal To
__________________
 
Reply With Quote
Old 07-04-11, 07:36 PM   #5
iPod 30gb
 
Join Date: Aug 2009
Location: Widnes
Posts: 1,090
cono1717 is a jewel in the rough
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.
 
Reply With Quote
Old 07-04-11, 08:25 PM   #6
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
Is there are way to combine multiple if tags at once like you can in css?
__________________
 
Reply With Quote
Old 08-04-11, 12:57 AM   #7
Free The Gadgets
 
corky20's Avatar
 
Join Date: Jan 2007
Location: NI
Posts: 4,776
corky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to behold
Send a message via twitter to corky20
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!
__________________
GADGETS - WANT TO MAKE A GUEST POST? PM ME!

Spoiler
@freethegadgets
 
Reply With Quote
Old 08-04-11, 01:19 AM   #8
Mini Mac
 
chapperzUK's Avatar
 
Join Date: Nov 2009
Location: Southend, Essex
Posts: 3,056
chapperzUK is a jewel in the rough
Send a message via MSN to chapperzUK Send a message via twitter to chapperzUK
Quote:
Originally Posted by corky20 View Post
$result="it has been $weeks weeks, $days days, $hours $hours, $minutes minutes and $seconds seconds since $date1";
?>
I'm sure that will just output (although it wont output it yet as you need to put 'echo $result;' to output), not 100% sure as I haven't work in PHP for while:

Quote:
it has been $weeks weeks, $days days, $hours $hours, $minutes minutes and $seconds seconds since $date1
as you need to do this :

Code:
$result = "it has been " . $weeks . " weeks, " . $days . " days, " . $hours . " hours, " . $minutes . " minutes and " . $seconds . " seconds since " . $date1;
FINALLY, something I can help with. An IF statement would be the best way to do it and I recommend do it this way.

$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)
{

}
If you need any more help then gimme a nudge.

Last edited by chapperzUK; 08-04-11 at 01:20 AM..
 
Reply With Quote
Old 08-04-11, 01:36 AM   #9
Free The Gadgets
 
corky20's Avatar
 
Join Date: Jan 2007
Location: NI
Posts: 4,776
corky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to behold
Send a message via twitter to corky20
Quote:
Originally Posted by chapperzUK View Post
I'm sure that will just output (although it wont output it yet as you need to put 'echo $result;' to output), not 100% sure as I haven't work in PHP for while:



as you need to do this :

Code:
$result = "it has been " . $weeks . " weeks, " . $days . " days, " . $hours . " hours, " . $minutes . " minutes and " . $seconds . " seconds since " . $date1;
FINALLY, something I can help with. An IF statement would be the best way to do it and I recommend do it this way.

$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)
{

}
If you need any more help then gimme a nudge.
An IF statement wouldn't be the best way to do it though, as the periods don't stop, I think?. It's definitely the easier way to do it but just wouldn't work as you would have to create variables for years and they would eventually run out and it would stop working.

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!
__________________
GADGETS - WANT TO MAKE A GUEST POST? PM ME!

Spoiler
@freethegadgets

Last edited by corky20; 08-04-11 at 01:41 AM..
 
Reply With Quote
Old 08-04-11, 01:41 AM   #10
Mini Mac
 
chapperzUK's Avatar
 
Join Date: Nov 2009
Location: Southend, Essex
Posts: 3,056
chapperzUK is a jewel in the rough
Send a message via MSN to chapperzUK Send a message via twitter to chapperzUK
Quote:
Originally Posted by corky20 View Post
An IF statement wouldn't be the best way to do it though, as the periods don't stop. It's definitely the easier way to do it but just wouldn't work as you would have to create variables for years and they would eventually run out and it would stop working.

The way I done it will work indefinitely and once coded won't have to be touched again!
ah my bad, read it and thought it said that it would do it for a year and then stop, don't have a clue where I got that from though. Silly me!
 
Reply With Quote
Old 08-04-11, 01:44 AM   #11
Free The Gadgets
 
corky20's Avatar
 
Join Date: Jan 2007
Location: NI
Posts: 4,776
corky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to beholdcorky20 is a splendid one to behold
Send a message via twitter to corky20
Quote:
Originally Posted by chapperzUK View Post
ah my bad, read it and thought it said that it would do it for a year and then stop, don't have a clue where I got that from though. Silly me!
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!
__________________
GADGETS - WANT TO MAKE A GUEST POST? PM ME!

Spoiler
@freethegadgets
 
Reply With Quote
Old 08-04-11, 12:42 PM   #12
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
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.
__________________
 
Reply With Quote
Old 09-04-11, 12:37 PM   #13
iPod 30gb
 
Join Date: Aug 2009
Location: Widnes
Posts: 1,090
cono1717 is a jewel in the rough
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";
}
But as you say it would need re-programming every year.
__________________
Totally Free iPad | McFlurry Ice Cream Van

Everything I say reflects my own opinions and not that of any company.
 
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off





All times are GMT. The time now is 08:57 PM.
All trademarks and copyrights held by respective owners. Forum posts are owned by the poster.

Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO
no new posts