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 7 of 7
  1. #1
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post

    Format date from a string

    Say I have a date in a string, "10 04 2003". Is there a function to convert the date into another format? I had a look through the documentation but didn't find it..

    I imagine that PHP would have one, I mean even ASP can do it.
    Omnis mico antequam dominus Spookster!

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    Somewhere far beyond
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    use this functions:
    --
    strtotime
    (PHP 3>= 3.0.12, PHP 4 >= 4.0.0)

    strtotime -- Parse about any English textual datetime description into a UNIX timestamp
    --
    date
    (PHP 3, PHP 4 >= 4.0.0)

    date -- Format a local time/date
    Description
    string date ( string format [, int timestamp])
    Returns a string formatted according to the given format string using the given integer timestamp or the current local time if no timestamp is given.
    WBR, Weirdan.

  • #3
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok I think I get what you told me, plus I looked it up in the manual but I'm still getting an error on the line where I use date()..
    PHP Code:
        $timestamp mysql_result($result,$i,"makedate") or die("Unable to extract date!");
        
    $timestamp strtotime($timestamp);
        
    $makedate date("d M y"$timestamp); 
    TIA!

    [edit:]Warning: unexpected error in date() in c:\phpdev\www\news_cast.php on line 24
    Last edited by Mhtml; 04-10-2003 at 02:29 PM.
    Omnis mico antequam dominus Spookster!

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    Somewhere far beyond
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Naturally.

    $makedate_=_date("d M y",_$timestamp));
    ---------------------------------------^^^
    Unmatched parenthesis
    WBR, Weirdan.

  • #5
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Hehe, I noticed that before I edited but after fixing I get the error in red..
    Omnis mico antequam dominus Spookster!

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    Somewhere far beyond
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1970-09-17 # ISO 8601.
    70-9-17 # This century assumed by default.
    70-09-17 # Leading zeros are ignored.
    9/17/72 # Common U.S. writing.
    24 September 1972
    24 Sept 72 # September has a special abbreviation.
    24 Sep 72 # Three-letter abbreviations always allowed.
    Sep 24, 1972
    24-sep-72
    24sep72

    PHP Code:
    $timestamp="10/04/03";
    $timestamp=strtotime($timestamp);
    $makedate=date("d M y",$timestamp);
    echo 
    $makedate
    It works for me
    WBR, Weirdan.

  • #7
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Aahh Okies! I had 10 04 2003 .. spaces. Thankyou weirdan!
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

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