|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gfaieta Guest
|
Posted: Sat Apr 19, 2003 2:34 pm Post subject: New timestamp format in smarty_make_timestamp() |
|
|
As of version 2.5.0 of Smarty the only possible format for timestamps is YYYYMMDDHHMMSS.
MySQL also uses a different format for datetimes YYYY-MM-DD HH:MM:SS so it would be useful to include a parser for such a format too.
Following is a possible code snippet for the new functionality:
Code: |
// is mysql datetime format of YYYY-MM-DD HH:MM:SS?
if (ereg( '^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$', $string )) {
$time = mktime(substr($string,11,2),substr($string,14,2),substr($string,17,2),
substr($string,5,2),substr($string,8,2),substr($string,0,4));
return $time;
}
|
Obviously, some optimizations can be used in the code (only allow 0-6 as the first digit for seconds, ...) but it gives a rough idea.
Gianluca |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sat Apr 19, 2003 5:18 pm Post subject: |
|
|
smarty_make_timestamp() should be able to take just about any format, is uses strtotime() to parse it. Did you try your format? It should work fine.
Code: |
{"2003-04-01 12:33:03"|date_format}
|
Monte |
|
Back to top |
|
gfaieta Guest
|
Posted: Mon Apr 21, 2003 8:32 am Post subject: |
|
|
oops,
you're right. Reading the manual I believed that only unix timestamps and mysql timestamps were accepted; reading the source I didn't find anything new. So I started hacking even before trying.
... strtotime() and similar magic functions ... what a beautiful thing
Maybe, a few more examples in the manual could be useful.
Thanks,
Gianluca |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|