Jump to content

Archived

This topic is now archived and is closed to further replies.

DataSpy

Help with time in php

Recommended Posts

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!

Share this post


Link to post
Share on other sites
[!--quoteo(post=382692:date=Jun 12 2006, 12:01 AM:name=DataSpy)--][div class=\'quotetop\']QUOTE(DataSpy @ Jun 12 2006, 12:01 AM) [snapback]382692[/snapback][/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
[code]
<?
$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";
}
?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.