w3resource

PHP Date Exercises : Print: Saturday the 7th

PHP date: Exercise-9 with Solution

Write a PHP script to print like : Saturday the 7th

Sample Solution:

PHP Code:

<?php
echo date('l \t\h\e jS'); // Outputs the current day of the week followed by the day of the month with the suffix.
?>

Output:

Tuesday the 11th 

Explanation:

In the exercise above,

  • date('l \t\h\e jS'): Formats the current date and time according to the provided format string.
  • l: Represents the full name of the day of the week (e.g., Monday, Tuesday, etc.).
  • \t\h\e: Outputs the literal text "the" as part of the string.
  • jS: Represents the day of the month with the suffix (e.g., 1st, 2nd, 3rd, etc.).
  • echo: Outputs the formatted date string to the screen.

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP script to get the first and last day of a month from a specified date.
Next: Write a PHP script to check whether the given dates are valid or not?

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php-exercises/php-date-exercise-9.php