Results 1 to 11 of 11

Thread: retrieve day,month and year from date

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    93

    retrieve day,month and year from date

    hi,
    i want do retrieve a dau,month,year from a date that i give
    how can i do that?
    thanks for your help

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: retrieve day,month and year from date

    depends on how it is formated. give us an example
    My usual boring signature: Something

  3. #3
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: retrieve day,month and year from date

    Use regular expressions or strtotime()
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    93

    Re: retrieve day,month and year from date

    hi,
    i have a problem in format of the data to.
    in my local server they store in this format:2002-2-12
    but in the real server in store in this format:2-12-2002
    so how can i retrieve from a format that i want?
    thanks for your help

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: retrieve day,month and year from date

    date()

    PHP Code:
    echo date("j-n-Y"); 
    j - Month Number (without prefixed 0 ) [1-12]
    n - day of month (without prefixed 0 ) [1-31]
    Y - full year [1999]

    check this out for more info: http://us2.php.net/date
    My usual boring signature: Something

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: retrieve day,month and year from date

    Dclamp, If the date is stored as a string. The date() function is of no use. You will have no choice by to use a regular expression to extract the individual components of the date and pass them to the mktime() function to create time stamp.

    You can then pass it to the date function or the strftime function to get it in the format you need.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: retrieve day,month and year from date

    he said he doesn't know how to format it, so i was showing him how to
    My usual boring signature: Something

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: retrieve day,month and year from date

    Quote Originally Posted by dclamp
    he said he doesn't know how to format it, so i was showing him how to
    The date function only formats timestamps not strings. You need to get the string into a timestamp before you can use the date() function on it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: retrieve day,month and year from date

    Such as the following:
    PHP Code:
    echo date("j-n-Y"strtotime(/*DATE VAR HERE*/)); 
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: retrieve day,month and year from date

    If you are using PHP version 5.2.0+ you can use the DateTime class to manipulate timestamps.
    Note that while the manual says version 5.1.0, it is not in fact enabled by default until 5.2.0.

  11. #11
    Addicted Member mfurqan's Avatar
    Join Date
    Oct 2005
    Location
    Pakistan
    Posts
    176

    Smile Re: retrieve day,month and year from date

    I am not sure if you actually need it but if the Date is "2007-08-20" (YYYY-MM-DD). Then

    PHP Code:
    <?PHP

     $Date 
    "2007-08-20";
     
    $Explode_Date explode("-"$Date);

     echo(
    "Year: $Explode_Date[0]");
     echo(
    "Month: $Explode_Date[1]");
     echo(
    "Date: $Explode_Date[2]");

    ?>
    Muhammad Furqan Attari.

Posting Permissions

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



Click Here to Expand Forum to Full Width