WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : formating MySQL Timestamp to get a propper Output. related : Timestamp, ereg_replace, mysql, substr
Categories : MySQL, PHP, Date Time, Databases Update Picture
amalesh kempf
Date : Apr 15th 1998
Grade : 3 of 5 (graded 3 times)
Viewed : 19569
File : No file for this code example.
Images : No Images for this code example.
Search : More code by amalesh kempf
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

/******************************************************************************

formating MySQL Timestamp to get a propper Output

Author         : Andreas Kempf
Date                : 1998-04-08

$svDate : The timestamp from MySQL
$svDateOutput : YYYY-MM-DD hh:mm:ss
DD.MM.YYYY or whatsoever

year = YYYY
month = MM
day = DD
hour = hh
minute= mm
second= ss

******************************************************************************/
<?
        function FncChangeTimestamp ($svDate, $svDateOutput)
        {
                $year = substr($svDate,0,4);
                $month = substr($svDate,4,2);
                $day = substr($svDate,6,2);
                $hour = substr($svDate,8,2);
                $minute= substr($svDate,10,2);
                $sec = substr($svDate,12,2);

                $svDateOutput = ereg_replace ("YYYY", $year, $svDateOutput);
                $svDateOutput = ereg_replace ("MM", $month, $svDateOutput);
                $svDateOutput = ereg_replace ("DD", $day, $svDateOutput);
                $svDateOutput = ereg_replace ("hh", $hour, $svDateOutput);
                $svDateOutput = ereg_replace ("mm", $minute, $svDateOutput);
                $svDateOutput = ereg_replace ("ss", $sec, $svDateOutput);
                
                return $svDateOutput;
        };
?>



Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time
mysql date/time converters
Categories : PHP, MySQL, Databases, Date Time
Data Retrieve from Mysql using AJAX with PHP
Categories : PHP, AJAX, Date Time, Databases, MySQL
How to Convert a MySQL Timestamp to a USA Date & Time
Categories : PHP, MySQL, Databases, Date Time
Phorum, MySQL, Language, UK date format, MySQL UK Date format
Categories : PHP, Date Time, Strings, MySQL, Databases
List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP
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
Simple function to return the number of days in a time span between 2 given dates.
Categories : PHP, Date Time, MySQL, Databases
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
Checks Date-Input from HTML-Forms and converts to YYYY-MM-DD Format for MySQL Date-Fields
Categories : MySQL, Date Time, PHP, Databases
Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, 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
How to Insert a Date Format Into MySQL from PHP
Categories : PHP, Databases, MySQL, Date Time, Beginner Guides
bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend.
Categories : Databases, PHP, ODBC, MySQL, PostgreSQL
 Camden wrote : 265
It`s so much easier just to use one of PHP`s built in date 
formatting functions.

For example:

echo strftime ("%b %d %Y %H:%M:%
S",$TimeStamp])."\n";
 
 Camden wrote : 266
Good job on the code kempf - just noticed the MySQL 
timestamps don`t convert with the built in functions.
 
 Jamez Picard wrote : 1052
You just have do your MySQL query right and you can use the date() function.
// SELECT UNIX_TIMESTAMP(your_mysql_timestamp_column_here) as yourdate from yourtable

echo date("l, F jS, Y at g:i", $yourdate);
 
 Sander van der Linden wrote : 1230
that might be so, but i have tables with lots of fields
 and it gets on your nerves if you HAVE to specify for 
each field to query what its name is and how to read it 
when you need all the fields anyway
 
 Sander van der Linden wrote : 1231
this is the same function modified for DATETIME:
thanks for it btw, very handy

<?
function func_change_datetime($svDate$svDateOutput)
    {
        
$year  substr($svDate,0,4);
        
$month substr($svDate,5,2);
        
$day   substr($svDate,8,2);
        
$hour  substr($svDate,11,2);
        
$minutesubstr($svDate,14,2);
        
$sec   substr($svDate,17,2);
        
        
$svDateOutput ereg_replace ("YYYY"$year$svDateOutput);
        
$svDateOutput ereg_replace ("MM"$month$svDateOutput);
        
$svDateOutput ereg_replace ("DD"$day$svDateOutput);
        
$svDateOutput ereg_replace ("hh"$hour$svDateOutput);
        
$svDateOutput ereg_replace ("mm"$minute$svDateOutput);
        
$svDateOutput ereg_replace ("ss"$sec$svDateOutput);
            
        echo 
$svDateOutput;
    };
?>
 
 taoufik bouaraar wrote :1251
i can`t get this code working
what should i define as var`s ... and what should i do to output the result "i`m a beginner"

Kind Regards