Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Here is a quick example of getting a Database-friendly time and date stamp,
- // so, for instance, if you were recording when files where stored in a database
- // file, you might:
- /**
- * $dbDate = $this->getTimeAndDate();
- * $query = mysql_query ( "INSERT INTO `" . $this->dbPrefix . "my_pictures` "
- * . "(`file_path`, `file_name`, `cat_id`, `date`) VALUES "
- * . "('" . $this->dir . "', "
- * . "'" . $this->imgData['fileName'] . "', "
- * . "'" . $this->imgData['category'] . "', "
- * . "'" . $dbDate . "')"
- * );
- **/
- // Here is the function:
- public function getTimeAndDate() {
- $date = getdate();
- $time = '';
- $dbDate = '';
- if((int)$date['hours']<10) {
- $time .= '0' . $date['hours'];
- } else {
- $time .= $date['hours'];
- }
- $time .= ':';
- if((int)$date['minutes']<10) {
- $time .= '0' . $date['minutes'];
- } else {
- $time .= $date['minutes'];
- }
- $time .= ':';
- if((int)$date['seconds']<10) {
- $time .= '0' . $date['seconds'];
- } else {
- $time .= $date['seconds'];
- }
- $dbDate = $date['year'] . '-';
- if((int)$date['mon']<10) {
- $dbDate .= '0' . $date['mon'];
- } else {
- $dbDate .= $date['mon'];
- }
- $dbDate .= '-';
- if((int)$date['mday']<10) {
- $dbDate .= '0' . $date['mday'];
- } else {
- $dbDate .= $date['mday'];
- }
- $dbDate .= ' ' . $time;
- return $dbDate;
- }
- // Simple!
- // @Author: Shaun B
- // @Date: 2013-02-21
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement