11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 12 • DATE AND TIMEecho "Today is ".date("F d, Y");// Today is August 22, 2010The next example demonstrates how to output the weekday:echo "Today is ".date("l");// Today is WednesdayLet’s try a more verbose presentation of the present date:$weekday = date("l");$daynumber = date("jS");$monthyear = date("F Y");printf("Today is %s the %s day of %s", $weekday, $daynumber, $monthyear);This returns the following:Today is Sunday the 22nd day of August 2010You might be tempted to insert the nonparameter-related strings directly into the date() function,like this:echo date("Today is l the ds day of F Y");Indeed, this does work in some cases; however, the results can be quite unpredictable. For instance,executing the preceding code produces the following:EDT201024pm10 1757 Monday 3103America/New_York 2457 24pm10 2010f May 2010Note that punctuation doesn’t conflict with any of the parameters, so feel free to insert it asnecessary. For example, to format a date as mm-dd-yyyy, use the following:echo date("m-d-Y");// 04-26-2010Working with TimeThe date() function can also produce time-related values. Let’s run through a few examples, startingwith simply outputting the present time:echo "The time is ".date("h:i:s");// The time is 07:44:53But is it morning or evening? Just add the a parameter:273

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!