Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Functions Bank

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR

Hello!

Why not having people post their own PHP functions here?
In my opinion, it would be a great benefit for us, beginners and pros,
because we would have plenty of code to study and to improve.

I'll start with a very simple function that outputs different
date formats I often use with dates taken from mysql (YYYY-MM-DD).

( the Japanese format won't correctly show up here, but you get the picture. )

function format_sqldate($date, $num) {

$method = array(
// ENGLISH FORMATS
"F d, Y", // [0] -> March 30, 2003
"l dS of F Y", // [1] -> Sunday 30th of March 2003
"D, d M Y", // [2] -> Sun, 30 Mar 2003
// FRENCH FORMATS
"d/m/Y", // [3] -> 30/03/2003
"d/m/y", // [4] -> 30/03/03
// JAPANESE FORMATS
"Y”N nŒŽ j“ú" // [5] -> 2003”N 3ŒŽ 30“ú
);

$date = explode("-", $date);
$date = date ($method[$num], mktime (0,0,0,$date[1],$date[2],$date[0]));

return $date;

}

Calling format_sqldate("2003-03-30", 1); will output Sunday 30th of March 2003.

Have a nice day!
 
Why reinvent the wheel and not let the database do it's job? //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top