public function listAllMyPublishedArticles($uid) {
$query="SELECT article_tbl.aid,header,introduction,body,published_state, FROM_UNIXTIME(published_date, '%d/%m/%y %H:%i') as published_date FROM article_tbl, user_has_art_tbl WHERE user_has_art_tbl.uid= $uid AND user_has_art_tbl.aid = article_tbl.aid AND article_tbl.published_state = 1 ORDER BY aid desc";
$query=mysql_query($query)or die(mysql_error());
return $query;
}
Tag Archive for timestamp
snippets |
May 12, 2012
from_unixtime sql
snippets |
March 16, 2012
MySQL Unix Timestamps
SELECT min( FROM_UNIXTIME(timestamp, '%Y') ) AS min_year FROM calendar_dates
snippets |
February 20, 2012
create_timestamp
function create_timestamp($date) { // Format : DD.MM.YYYY
if (preg_match("/^([0-9]{1,2}).([0-9]{1,2}).([0-9]{4})$/i",$date))
{
$expDate=explode(".",$date);
if(strlen($expDate[0])=="1"){$expDate[0]="0".$expDate[0];}
if(strlen($expDate[1])=="1"){$expDate[1]="0".$expDate[1];}
return mktime(0,0,0,$expDate[1],$expDate[0],$expDate[2]);
}
else return false;
}
snippets |
February 9, 2012
unix timestamp to date
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty convert to unix
*
* Type: modifier
* Name: convertunix
* Purpose: convert unix timestamp to date
* @author Frank Broersen
* @param string
* @return string
*/
function smarty_modifier_convertunix($sString,$sFormat)
{
return gmdate($sFormat, $sString);
}
?>
snippets |
January 3, 2012
PHP – 12hs to 24hs
function hours12ToTimestamp24( $hora ){
#Saco solo hora y min en un array
$horaArray = explode(":", $hora);
if( sizeof( $horaArray ) < 2 ) return 0;
#Si tiene pm en el string le sumo 12 hs al mod de la hora sobre 12.
$extra = strstr(strtolower($hora), 'pm') || strstr(strtolower($hora), 'p.m')? 12 : 0;
return mktime(($horaArray[0]%12)+$extra, $horaArray[1], 0, 1, 1, 1970 );
}
snippets |
December 15, 2011
Translate amount of seconds to hours, minutes, seconds
Duration is a function used to turn seconds into a readable format, measured in weeks, days, hours, minutes and seconds.
Highlight: PHP
<?php
function duration($secs)
{
$vals = array('w' => (int) ($secs / 86400 / 7),
'd' => $secs / 86400 % 7,
'h' => $secs / 3600 % 24,
'm' => $secs / 60 % 60,
's' => $secs % 60);
$ret = array();
$added = false;
foreach ($vals as $k => $v) {
if ($v > 0 || $added) {
$added = true;
$ret[] = $v . $k;
}
}
return join(' ', $ret);
}
?>
Sample usage
Highlight: PHP
<?php
$dateOfBirth = $someTimestamp;
$ageInSeconds = time() - $dateOfBirth;
echo 'I am ' . duration($ageInSeconds) . ' old';
?>
snippets |
October 28, 2011
Format Date
function dater($format = "", $date = "")
{
if($format == "") $format = "Y-m-d H:i:s";
if($date == "") $date = time();
$converted = strtotime($date);
if($converted === false)
return date($format, $date);
else
return date($format, $converted);
}