Results 1 to 5 of 5

Thread: [RESOLVED] Date format

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Resolved [RESOLVED] Date format

    Its back to basics i think

    My datae is stored in MySQL database in this format DD-MM-YYYY HH-MM-SS (the timestamp format)

    I need to format this and preferable outside of the MySQL query statement, now what formatting function do i use, i have tried various, with little result.

    Cheers people

  2. #2

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Date format

    I have solved the problem by creating a function to take the time from the timestamp, split it up, and format it using date and mktime. I have included it for future refernce,m if anyone spots an issue, gives us a shout

    PHP Code:
    function format_date($timestamp_date=''
    {
        if(
    $timestamp_date=='')
        {    
            
    // Return if no variables passed
            
    return;
        }
        else
        {    
            
    // Split up date and time
            
    $date_time split(" "$timestamp_date); 
            
            
    // Split up date
            
    $date split("-"$date_time[0]);
            
            
    // Split up time
            
    $time split("-"$date_time[1]);
            
            
    $result=date("l jS F Y"mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0]));
        }
        return 
    $result;
        


  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] Date format

    if I were you, I'd just store them as unix timestamps and convert them to whatever I need to at runtime. It depends what you're comfortable with, I guess.

  4. #4

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: [RESOLVED] Date format

    Yes i was told this before by visualad, however im using phpMyAdmin, and i cant seem to find the unix timestamp option :O

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] Date format

    when you're creating a table you just need to make your date fields an integer that holds 11 figures (ie: int(11)) instead of "date" or "timestamp" types.

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