Jump to content

Help with time in php


DataSpy

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!
Link to comment
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]
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.