Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re-Formatting a Date

    I am extracting a date from the database and it comes out in the format yyyy-mm-dd. In my page I would like to be able to refer to all three parts of this date as seperate variable.

    I know how to format the current date using date() and I know how to format the results within the SQL select. My issue is reformatting a date from 'yyyy-mm-dd' to 'dd-mm-yy' or to just 'yyyy' etc.

    Can this just done through php with some kind of function which does this?

    Thanks
    Last edited by Candrias77; 04-07-2003 at 05:57 AM.
    eTheory - the theory of revolution

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why not post this in the PHP forum?

    Anyway, this tell you all you need + it's the best site to look up this sort a thing (in addition to the PHP forum)

    http://www.php.net/manual/en/function.strtotime.php


    Look for his usercomment. Think it's exactly what you need.
    dontspam at technohac dot com
    16-Apr-2002 10:47

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks raf, originally I thought this was going to be an SQL question as it involved extracting data in the correct format but indeed it ended up as a 100% php question... in the end explode("-",dataFromMySQL) solved my problem
    eTheory - the theory of revolution

  • #4
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is indeed a PHP query...

    for reference, here's a little function i made that will wort out YYMMDD into dd-mm-yy

    PHP Code:
    function rfixdate($date)
    {
      
    $year substr($date,0,2);
      
    $month substr($date,2,2);
      
    $day substr($date,4,4);
      return 
    $day."/".$month."/".$year;

    I'll move this to the PHP forum too

    Jee
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting


  •  

    Posting Permissions

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