toonz Posted November 30, 2008 Share Posted November 30, 2008 I have added a line item on one of my .tpl pages to show the date. since it is pulling the datetime stamp from the db, it shows a date like 1226325111 right now. since the info is being pulled from <td><B>{$ctoninfo.release_date}</B> </td> how do I alter the code to only display the date formatted to 'mm-dd-yyyy'? thanks in advance Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/ Share on other sites More sharing options...
jscix Posted November 30, 2008 Share Posted November 30, 2008 SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y') Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702283 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 If your column in your database holds a Unix Timestamp, you can convert and format it using the mysql FROM_UNIXTIME(unix_timestamp,format) function in your query. Use the same format string that jscix gave in the DATE_FORMAT example. Ref: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_from-unixtime Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702288 Share on other sites More sharing options...
toonz Posted November 30, 2008 Author Share Posted November 30, 2008 so how/where do I insert it into the string {$ctoninfo.release_date} thanks Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702292 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 You don't. You do that in your mysql SELECT query that is retrieving the data from the database. Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702295 Share on other sites More sharing options...
toonz Posted November 30, 2008 Author Share Posted November 30, 2008 ah, well since I have 0 experience coding php, I dont think I will be altering the php file. I have only been working on the ptl files to change layouts and formatting Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702296 Share on other sites More sharing options...
toonz Posted November 30, 2008 Author Share Posted November 30, 2008 ok, say I add this line towards the top of the php file $str_sql = "select DATE_FORMAT(FROM_UNIXTIME(release_date), '%m/%d/%Y')"; in the tpl file, I changed the target from {$ctoninfo.release_date} to {$release_date} now instead of pulling up a datetime string of numbers, it gives a blank space. how do I make it so that template knows to pull the newly converted timestamp from the php file? thanks again Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702312 Share on other sites More sharing options...
Mchl Posted November 30, 2008 Share Posted November 30, 2008 Are you using Smarty? Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702332 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2008 Share Posted November 30, 2008 You would not change {$ctoninfo.release_date} in the template, you would change the existing code that queries the database and places the content into that variable. Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702334 Share on other sites More sharing options...
Mchl Posted November 30, 2008 Share Posted November 30, 2008 In smarty you could actually use date_format modifier. That's one of the ideas behind templates. Template designer does not have to (should not!) modify database code. Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702335 Share on other sites More sharing options...
toonz Posted November 30, 2008 Author Share Posted November 30, 2008 yes, from the looks of the code there is smarty. I see a row like $smarty->assign("toon_path",$tpth); so how do have the tpl pull the newly formatted date into the actual template to display on the web page? thanks Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702348 Share on other sites More sharing options...
Mchl Posted November 30, 2008 Share Posted November 30, 2008 {$ctoninfo.release_date|date_format:"%m-%d-%Y"} Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702354 Share on other sites More sharing options...
toonz Posted November 30, 2008 Author Share Posted November 30, 2008 Mchl, youre brilliant! worked like a charm. thanks Link to comment https://forums.phpfreaks.com/topic/134878-converting-datetime-format/#findComment-702367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.