PHPBuilder - Easy dates



RSS Twitter
Snippets Calendars Dates

Easy dates

by: jonseddon
|
August 6, 2006

Version: 1.0

Type: Sample Code (HOWTO)

Category: Calendars/Dates

License: GNU General Public License

Description: A short piece of code to help move dates and times around. Store the date and time in one column in mysql and use this to help display it however you want. My first post and first explode() function. A very proud moment.



Let's assume that the date goes into a column as
follows

$date = (date ("Y-m-d H:i:s")); 

Mysql_query("select * ...");
the date being in the array as:-
$date = $row['date'];

//begin

$dte = explode("-", $date);{      // breaks the array
    $Year = $dte[0];              // the year
    $month = $dte[1];             // the month
    $dt = $dte[2];                // the day + time
    $d_te = explode (" ", $dt);{  // explode again
    $day = $d_te[0];              // The day
    $time = $d_te[1];             // The time
    }
    $final_date = $day.'/'.$month.'/'.$Year;   
    }

//end

$final_date is now a nice European format. Squiff it around to :-

$final_date = $month.'/.$day.'/'.$Year;

for the yanks and $tim is the time.

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
jonseddon

Comment:



Comment:

(Maximum characters: 1200). You have characters left.