elmas156 Posted September 5, 2008 Share Posted September 5, 2008 Hey everyone, I'm trying to take a specific date and check to see if it falls on a specific day of the week and use it in an if/else statement. For example: <?php if ($date falls on a Saturday or Sunday) { echo "I'm going to be at the lake on $date. Please choose another date."; } else { echo "Your appointment has been scheduled."; } ?> Obviously, what I'm having problems with is checking to see if the date falls on a Saturday or Sunday. Does anyone have any ideas on how I could accomplish this? Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/ Share on other sites More sharing options...
Mchl Posted September 5, 2008 Share Posted September 5, 2008 getdate() Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634827 Share on other sites More sharing options...
joquius Posted September 5, 2008 Share Posted September 5, 2008 or date("l", $date) Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634829 Share on other sites More sharing options...
elmas156 Posted September 5, 2008 Author Share Posted September 5, 2008 I already know how to get the current date in the format that I need to use: <?php $cmonth=date("m"); $cday=date("d"); $cyear=date("Y"); $cdate=$cmonth ."/". $cday ."/". $cyear; ?> But is there a way to tell if a selected date (not the current date) falls on a specific day of the week? I already have the calendar/date selector in a form on the previous page (in this format: 09/05/2008). When the form is submitted it sends the selected date to schedule.php. I want to check to see if the selected date falls on a Saturday or Sunday. If so, the user will be alerted that appointment dates are not accepted on Saturday or Sunday, otherwise it will go on with the code and insert the information into the database and schedule the appointment. Thanks for any input. Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634848 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 date('i', strtotime($date)); Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634849 Share on other sites More sharing options...
elmas156 Posted September 5, 2008 Author Share Posted September 5, 2008 I really appreciate your help but I'm still confused as to exactly how I would use this function. Could you please elaborate on your solution? Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634864 Share on other sites More sharing options...
DarkWater Posted September 5, 2008 Share Posted September 5, 2008 My bad, I used 'i' instead of 'l'. Wasn't paying attention. You could do it like this: <?php $date = '8/8/2008'; echo date('l', strtotime($date)); ?> Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634878 Share on other sites More sharing options...
elmas156 Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks very much! I've been trying to figure out how to do that for hours. I think I can make it work now. Thanks again! Link to comment https://forums.phpfreaks.com/topic/122917-comparing-a-date-to-see-what-day-it-falls-on/#findComment-634890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.