Reputation: 2309
i put date in mysql database with this method 2012-08-02 02:20:05
. now, how to print in my page using smarty.
mycode : ( NOTE: send_date is name of row )
$sql = "SELECT m.*, s.photo, s.gender
FROM mail AS m, signup AS s
WHERE m.receiver = '" .mysql_real_escape_string($username). "'
AND m.sender = s.username AND inbox = '1' AND status = '1'
ORDER BY send_date DESC LIMIT " .$limit;
$rs = $conn->execute($sql);
Upvotes: 0
Views: 997
Reputation: 13557
To convert a date from 2012-08-02 02:20:05
to unix epoch (seconds since 1970), you want to use strtotime(). To format an epoch to any human readable date you want to use date() or strtotime().
Smarty knows the date_format modifier. Since Smarty3 this puppy accepts pretty much anything that represents a date (including 2012-08-02 02:20:05
). In Smarty2 you might need to convert the string to epoch yourself, something like {$date|strtotime|date_forma:"%d.$m.%Y"}. Note that since Smarty3 date_format accepts format notations from strtotime and date, while Smarty2 only supported the strtotime notation.
Upvotes: 2
Reputation: 4849
If you're asking how to output any variable in smarty do the following (assuming your smarty is set up correctly):
In PHP:
/*
assign method: assigns variables to the template
first parameter: The variable name you want to use in your template file
second parameter: the parameter you want to pass to your template file
*/
$smarty->assign('variable', $variable);
In smarty:
/*
brackets {} indicate that smarty is in play
$variable is the variable you passed to smarty
*/
{$variable}
If this is not what you're after please edit your question to be more clear.
Upvotes: 0