-2

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

Deex
  • 317
  • 2
  • 13
  • Please start with some php basic tutorials. We are not a code writing service here nor a school – Rizier123 Jul 15 '15 at 05:43
  • I never said i wanted a full code, a tutorial or simlar were also great because i didn't found something on google. So i don't know why you are so angry about. – Deex Jul 15 '15 at 05:55
  • possible duplicate of [Checking if date falls on weekday or weekend?](http://stackoverflow.com/questions/9553731/checking-if-date-falls-on-weekday-or-weekend) – Sougata Bose Jul 15 '15 at 06:00

4 Answers4

1

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";
}
Pratik Soni
  • 2,498
  • 16
  • 26
0

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

Wee Zel
  • 1,294
  • 9
  • 11
  • Thank you, sadly some other was faster – Deex Jul 15 '15 at 05:51
  • no problem @Deex, don't forget you can make things cooler by adding extra e.g. if I'm lazy and want to be reminded on the 1st Wed of the month `if (date('D') === 'Wed' and date('j') <= 7)` – Wee Zel Jul 15 '15 at 06:08
0

Use date('w'):

if (date('w')==3)
  print "Hey today you have to wash your car?";
Ondřej Šotek
  • 1,793
  • 1
  • 15
  • 24
0

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;
}
Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52