sadly i'm not familar with php, but is it possible to Echo a Text only if it is a specific day of a week? As Example if it's Wednesday to echo "Hey today you have to wash your car?" and if it is not that day to show nothing?
Sinclery Yours
sadly i'm not familar with php, but is it possible to Echo a Text only if it is a specific day of a week? As Example if it's Wednesday to echo "Hey today you have to wash your car?" and if it is not that day to show nothing?
Sinclery Yours
Yes there is. This wil be your answer.
The date function Formats a date . It Returns a string formatted according to the given format string.
It accepts 2 arguments.
1st - (string). Should be valid format. Check for possible formats
2nd - (int). It is optional. It accepts timestamps. The default value will be current time stamp
$day = date('D');
if (strtolower($day)=='wed')
{
echo "Today is Wednesday";
}
something like this?
<?php
if (date('D') === 'Wed')
echo "Hey today you have to wash your car?"
read about the date function, there's lots of bits it can return
Use date('w'):
if (date('w')==3)
print "Hey today you have to wash your car?";
You can get the current day of the week using the date()
function. The function returns different things depending on what you put in the first argument. You can find what those things are in the documentation (link above). "w"
tells the function to return the day of the week:
$dayOfWeek = date("w");
The variable now contains a number representing the day of the week, starting from 0
(Sunday) to 6
(Saturday). In other words:
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
If you only want to target Wednesday then you can use an if
block:
if ($dayOfWeek == 3) {
echo 'Hey today you have to wash your car!';
}
If you want to target more than one day then you can use a switch
block:
switch ($dayOfWeek) {
case 0: // Sunday
case 6: // Saturday
echo 'Good weekend! Enjoy it!';
break;
case 3: // Wednesday
echo 'Hey today you have to wash your car!';
break;
}