DataSpy Posted June 12, 2006 Share Posted June 12, 2006 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 Link to comment https://forums.phpfreaks.com/topic/11754-help-with-time-in-php/ Share on other sites More sharing options...
redarrow Posted June 12, 2006 Share Posted June 12, 2006 [!--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] Quote Link to comment https://forums.phpfreaks.com/topic/11754-help-with-time-in-php/#findComment-44459 Share on other sites More sharing options...
AndyB Posted June 12, 2006 Share Posted June 12, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11754-help-with-time-in-php/#findComment-44467 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.