SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    Try this:

    PHP Code:

    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
    Last edited by John_Betong; Feb 16, 2012 at 07:07. Reason: formatting

  3. #3
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's perfect, thank you very much.

    Neil

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    @Neilious,

    Welcome to the forum

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •