if time is now is new hour then..

This is a discussion on "if time is now is new hour then.." within the PHP Forum section. This forum, and the thread "if time is now is new hour then.. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Nov 7th, 2007, 14:33
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb if time is now is new hour then..

Hi,

Im trying to think of a way to write a piece of code that basiaclly does this.

If the time now is a new hour then...
If the time now is a new day then...
if the time is a new week then...
if the time now is a new month then...

once I have that I can create mysql tables at the right time to store data.

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Nov 7th, 2007, 14:45
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

That description is a bit cryptic. ^^

Do you want to check if it is a new hour since ANYBODY opened up the php page last time? Or just a specific IP? Or a user?

Anybody: Write information to text file, check text file with script.
IP / User: Use mysql table and write information for every ip/user in there. Check with script.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Nov 7th, 2007, 14:49
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

Sorry. I seem to be having one of those days where whatever I post I just confuse everybody.

No I want to get the php to check the server time and if the time is 15:59 then it is not a new hour since it last check at 15xx (stored in mysql table), but if the time was 16:02 then it would be a new hour so therefore continue.

Basically I need that to happen per hour, per day, per week, and per month.

Thanks.

Last edited by eon201; Nov 7th, 2007 at 14:53.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Nov 7th, 2007, 15:14
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: if time is now is new hour then..

Why not just use a cron job?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Nov 7th, 2007, 15:19
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

excuse my ignorance.... what is a cron job???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Nov 7th, 2007, 15:22
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

Whats going on, my post "use a cronjob" is gone... *grml* ^^

A Cronjob can be set at your webserver. It is a little timer (or more) which do something at a specific time.
You can set one "do stuff every hour" running one script, one "do stuff every 24hours" running another script.
Try Google: http://www.google.com/search?hl=en&q=cronjob
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Nov 7th, 2007, 15:36
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

oh right yer i know what you mean now. The problem is that the script will be run on the server once every fifteen minutes.

But within the script itself I need it to write to different mysql tables depending on the date/time for hours/days/weeks and months. And I really want it to all run within the one script.

Thanks so far, but any more suggestions#?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Nov 7th, 2007, 15:37
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: if time is now is new hour then..

Oh right, use the time() function.
http://uk2.php.net/time
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Nov 7th, 2007, 15:42
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

ok cool. But back to my original question..

How would I implement that to work out if this is a new hour,day,week or month comparitive to the last time that each corresponding mysql table was updated??

Thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Nov 8th, 2007, 06:28
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

The MYSQL Table has some implemented informations. One is "update time". You can check at which something was added or modified.
So get that update time form your table with
PHP: Select all

$info mysql_query("SHOW table status FROM yourdbname LIKE 'yourtablename'") or die (mysql_error());
$lastupdate $info["Update_time"]; 
And then you can compare it to the actual time(); timestamp.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Nov 8th, 2007, 13:33
Up'n'Coming Member
Join Date: Oct 2007
Location: london
Age: 25
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

After a lot of coming and going. I have come to the conclusion that I need the script to activate certain parts of itself at different times of the day (the whole script will re run every 20secs) eg. run part a at 15:45 and 16:00, run part b at 9:00 and :9:30.

I hope someone can help me with this as I am stumped!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Nov 9th, 2007, 07:29
Up'n'Coming Member
Join Date: Jun 2007
Location: Germany
Age: 23
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Re: if time is now is new hour then..

If you want the script to be executed at fixed times at the day, just get the current time
PHP: Select all

$time date("H:i");
if(
$time == "15:45")
{
  
// DO something at 15:45
}else
if(
$time == "09:00")
{
  
// Do something at 9:00
}
... and 
so on

Last edited by c010depunkk; Nov 9th, 2007 at 08:31. Reason: [code] became [php]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 Hour Website shawzy85 Free Web Site Critique 22 Jul 9th, 2008 19:24
4 hour Website shawzy85 Free Web Site Critique 8 Apr 28th, 2008 22:03
Every half hour script Blake121 PHP Forum 5 Aug 18th, 2007 10:29
Adjusting time from server time to local time Tim356 Classic ASP 10 Jun 21st, 2004 14:57
24 hour time calculation kinjiro JavaScript Forum 9 Sep 20th, 2003 06:40


All times are GMT. The time now is 17:57.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42