12

I want to use PHP date to write something like:

Generated Fri, Aug 30, 2013 at 1:00pm

using:

echo "Generated ".date('D, M j, Y at g:ia');

However, I cannot use the "at" because that is swapped with 00am

Is there a way to include the word at in the date formation without using two date()?

danielb
  • 878
  • 4
  • 10
  • 26

2 Answers2

16

You can escape characters in the output like this:

echo "Generated ".date('D, M j, Y \a\t g:ia');

The following is taken from the PHP Date function (http://php.net/manual/en/function.date.php):

<?php
// prints something like: Wednesday the 15th
echo date('l \t\h\e jS');
?>
Fluffeh
  • 33,228
  • 16
  • 67
  • 80
  • not work with my code. would you please help $last_modified_date = new DateTime(); $last_modified_date->format("l \a\t H:ia"); – Sachin Sarola Jul 13 '18 at 05:55
  • echo date("l \a\t H:ia"); also not worked I am using php 7.1.* version – Sachin Sarola Jul 13 '18 at 06:01
  • For escaping "t" it seems single quotes are necessary date('l \a\t H:ia'), my hunch is to do with it being a special character (tab) although curiously with "n" you can use two backslashes with double quotes ie. "\\n" – user36388 Apr 23 '20 at 08:26
3
echo "Generated ".date('D, M j, Y \a\t g:ia');
M.Svrcek
  • 5,485
  • 4
  • 25
  • 33