Jump to content


Photo

Help with time in php


  • Please log in to reply
2 replies to this topic

#1 DataSpy

DataSpy
  • Members
  • PipPipPip
  • Advanced Member
  • 54 posts

Posted 12 June 2006 - 12:01 AM

Hello, what I'm trying to do is check to see what time and day someone views a page and then echo a responce. I know what i want to do but I've never worked with time before and was a little confused.


example:

if it's between 7:00 AM and 11:59 AM and Monday
$shift = $monday_morning_shift;

then echo out

if $shift = $monday_morning_shift
echo 'something';

Any help greatly appretiated, thanx in advance!

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 12 June 2006 - 12:13 AM

[!--quoteo(post=382692:date=Jun 12 2006, 12:01 AM:name=DataSpy)--][div class=\'quotetop\']QUOTE(DataSpy @ Jun 12 2006, 12:01 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hello, what I'm trying to do is check to see what time and day someone views a page and then echo a responce. I know what i want to do but I've never worked with time before and was a little confused.
example:

if it's between 7:00 AM and 11:59 AM and Monday
$shift = $monday_morning_shift;

then echo out

if $shift = $monday_morning_shift
echo 'something';

Any help greatly appretiated, thanx in advance!
[/quote]

i am only learning but tried lol
<?
$shift_start="07:00:00";
$shift_end="11:59:21";
$day="monday";

if( ($shift_start ) && (< $shift_end) ){

echo"its your shift";

}else{

echo " not your shift";
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 June 2006 - 12:57 AM

What you need to do first is read (the manual) about the date() function and how to use it. You can format date and time in many different ways - simply. Check [a href=\"http://ca.php.net/manual/en/function.date.php\" target=\"_blank\"]http://ca.php.net/manual/en/function.date.php[/a]

The 'comparison' you'll need to make is between the time 'now' and the current day of the week to see if it's Monday between your selected times. As a cautionary note - php runs on your server which means that all times and dates will be those wherever your server exists and that may not be your time zone.

Alternatively, javascript runs on your local machine where you probably have the local time and javascript can determine the day of the week as well as the (local) time.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users