Like this code?
Show the author your appreciation.
I needed to create a custom blog application for a client. I created the table for the blogs with a timestamp field that updates itself on insert and on update. My problem was displaying the date in legible form to the blog community. I came up with this solution. Enjoy!
<?php
//connect to database here
$hosta = 'localhost' ;
$usera = 'database_user' ;
$passworda = 'database_password_for_database_user' ;
$namea = 'database_name_not_table_name' ;
$connection = @ mysql_connect ( $hosta , $usera , $passworda ) or die( mysql_error ());
$db = @ mysql_select_db ( $namea , $connection ) or die( mysql_error ());
//run SELECT statement here
$r = mysql_query ( "SELECT * FROM `database_table`" );
while( $row = mysql_fetch_array ( $r )){
$timestamp = $row [ 'timestamp' ];
$postedyear = substr ( $timestamp , 0 , 4 );
$postedmonth = substr ( $timestamp , 5 , 2 );
$postedday = substr ( $timestamp , 8 , 2 );
$postedtime = substr ( $timestamp , 11 , 5 );
$newpostedtime = "" ;
$nomilitary = substr ( $postedtime , 0 , 2 );
if( $nomilitary >= 13 ){
$nomilitary = $nomilitary - 12 ;
$newpostedtime = $nomilitary ;
$newpostedtime .= ":" ;
$newpostedtime .= substr ( $postedtime , 3 , 2 ) ;
$newpostedtime .= " pm" ;
}
if( $newpostedtime != "" ){
$postedtime = $newpostedtime ;
}else{
$postedtime .= " am" ;
}
//usage example:
echo "This blog was posted on: " . $postedmonth . "/" . $postedday . "/" . $postedyear . " at " . $postedtime . "<br><br>"
}
?>
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP , Arrays , Date Time , Databases , MySQL Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP , Date Time , Strings , MySQL , Databases PHP Calendar Web App Categories : PHP , Databases , MySQL , Date Time , Calendar List people whose birthdays fall on the current Day and Month
Categories : Databases , Date Time , MySQL , PHP In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date. Categories : PHP , Date Time , Databases , MySQL formating MySQL Timestamp to get a propper Output.
related : Timestamp, ereg_replace, mysql, substr Categories : MySQL , PHP , Date Time , Databases bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL , PHP , MySQL , Complete Programs , Databases Data Retrieve from Mysql using AJAX with PHP Categories : PHP , AJAX , Date Time , Databases , MySQL Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays. Categories : Calendar , Date Time , PHP , Databases , MySQL This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases , MySQL , Complete Programs , PHP , Databases Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields Categories : MySQL , Date Time , PHP , Databases How to Insert a Date Format Into MySQL from PHP Categories : PHP , Databases , MySQL , Date Time , Beginner Guides mysql date/time converters Categories : PHP , MySQL , Databases , Date Time Finding the day of the week for a specific date.
Categories : PHP , Databases , MySQL , Date Time Simple function to return the number of days in a time span between 2 given dates. Categories : PHP , Date Time , MySQL , Databases