Creating a week commencing date line

Hi I’m pretty new to PHP so please forgive me if this is obvious, but I’m having problems automatically displaying the date. I’ve managed to display week commencing and the date and month, but for some reason it’s displaying 'UTCb ’ after the month any ideas how I get rid of this. My code is as follows

<?php
$monday_this_week = date (‘d M’, strtotime ( date ( ‘Y’ ) . ‘W’ . date ( ‘W’ ) . ‘1’ ) ); //The last number is the num of the weekday. 0 being sunday.

echo "Week Commencing Monday ".date($monday_this_week);

?>

Any help would be appreciated

Thanks
Neil

Try this:



defined('jj') ? NULL : define('jj', '<br />');

$a=array
(
  'd  M y',     //  13 Feb 12
  'd  M Y',     //  13 Feb 2012
  'dS F y',     //  13th Feb 12
  'dS F Y',     //  13th Feb 2012
  'dS F y T',   //  13th Feb 2012Europe/Berlin
  'dS F y Tb',  //  13th Feb 2012Europe/Berlinb
);

$monday_this_week = strtotime ( date ( 'Y' ) . 'W' . date ( 'W' ) . '1');
foreach($a as $x):
  echo jj,  "Week Commencing Monday "
         .  'date(' ."'"
         .  $x
         .  "', "
         .  '$monday_this_week);';

  echo jj,  "Week Commencing Monday "
          . date($x, $monday_this_week);
  echo jj;
endforeach;

echo jj,jj, '// Your code:';

$monday_this_week = date ('d M', strtotime ( date ( 'Y' ) . 'W' . date ( 'W' ) . '1' ) ); //The last number is the num of the weekday. 0 being sunday.
echo jj, "Week Commencing Monday ".date($monday_this_week);echo jj, "Week Commencing MONDAY ".  date($monday_this_week);
echo jj;

echo jj, 'http://php.net/manual/en/function.date.php';


Output:

Week Commencing Monday date(‘d M y’, $monday_this_week);
Week Commencing Monday 13 Feb 12

Week Commencing Monday date(‘d M Y’, $monday_this_week);
Week Commencing Monday 13 Feb 2012

Week Commencing Monday date(‘dS F y’, $monday_this_week);
Week Commencing Monday 13th February 12

Week Commencing Monday date(‘dS F Y’, $monday_this_week);
Week Commencing Monday 13th February 2012

Week Commencing Monday date(‘dS F y T’, $monday_this_week);
Week Commencing Monday 13th February 12 CET

Week Commencing Monday date(‘dS F y Tb’, $monday_this_week);
Week Commencing Monday 13th February 12 CETb

// Your code:
Week Commencing Monday 13 FebruaryEurope/Berlinb
Week Commencing MONDAY 13 FebruaryEurope/Berlinb

http://php.net/manual/en/function.date.php&#65279;

That’s perfect, thank you very much.

Neil

@Neilious,

Welcome to the forum :slight_smile:

I learnt a little more about date(…) and strtotime(…)