[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Date & time problem

Posted on 2011-04-21
5
Medium Priority
?
185 Views
Last Modified: 2012-05-11
Hi Experts!

I have a small problem which I don't know how to tackle.

If the current date and time is between thursday 21:00 - friday 06:00 {
echo 'thursday';

} else if { the current date and time is between friday 21:00 - saturday 06:00 {
echo 'friday';

} else if { the current date and time is between saturday 21:00 to saturday 06:00 {
echo 'saturday';

} else { echo 'other'; }

How do I rewrite the text to php? I hope you understand :-)

Thanks in advance!
0
Comment
Question by:sittinDuck
  • 4
5 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 35443963
http://www.php.net/manual/en/function.date.php

string date ( string $format [, int $timestamp ] )

w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
D A textual representation of a day, three letters Mon through Sun
G 24-hour format of an hour without leading zeros 0 through 23
H 24-hour format of an hour with leading zeros 00 through 23

0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 35443985
so

$w = date("w");
$h = date("G");

if (($w==4 && H>21) or ($w==5 && H<6)) echo "Thursday";
...

may have some syntax errors :)
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 35444069
here it is
$w = date("w");
$h = date("G");

echo "W : ".$w." H:".$h;

if ((($w==0) and ($h>21)) or (($w==1) and ($h<6))) echo "Monday";
if ((($w==1) and ($h>21)) or (($w==2) and ($h<6))) echo "Tuesday";
if ((($w==2) and ($h>21)) or (($w==3) and ($h<6))) echo "Wednesday";
if ((($w==3) and ($h>21)) or (($w==4) and ($h<6))) echo "Thursday";
if ((($w==4) and ($h>21)) or (($w==5) and ($h<6))) echo "Friday";
if ((($w==5) and ($h>21)) or (($w==6) and ($h<6))) echo "Saturday";
if ((($w==6) and ($h>21)) or (($w==0) and ($h<6))) echo "Sunday";

Open in new window

0
 
LVL 61

Expert Comment

by:HainKurt
ID: 35444088
or this


$w = date("w");
$h = date("G");

//echo "W : ".$w." H:".$h;

if ((($w==3) and ($h>21)) or (($w==4) and ($h<6))) echo "Thursday"; else 
if ((($w==4) and ($h>21)) or (($w==5) and ($h<6))) echo "Friday"; else
if ((($w==5) and ($h>21)) or (($w==6) and ($h<6))) echo "Saturday"; else
echo "Other";

Open in new window

0
 

Author Comment

by:sittinDuck
ID: 35444106
Thank you HainKurt, that was exactly what I was looking for :-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question