SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 86 | Next

James Kennard

"Mastering Joomla! 1.5 Extension and Framework Development"

It is important that when we come to save dates and times we use the correct
format for the database that is being used.
Sadly, there is currently no way to ensure that we are using the format specific to the
database being used. Instead we must assume that the database is MySQL based.
This means that we must store dates in the format YYYY-MM-DD HH:MM:SS.
The easiest way to do this is to use the JDate class. JDate objects are used to parse
and represent date and time values. We use the toMySQL() method to ensure that the
value is formatted appropriately:
// import JDate class
jimport('joomla.utilities.date');
// get current date and time (unix timestamp)
$myDate = gmdate();
Chapter 3
[ 63 ]
// create JDate object
$jdate = new JDate($myDate);
// create query using toMySQL()
$query = 'SELECT * FROM #__example WHERE date < '.$jdate->toMySQL();
The value that we pass when creating the JDate object can be in the format UNIX
timestamp, RFC 2822 / 822, or ISO 8601. A more complete description of JDate is
available in Chapter 12.


Pages:
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6