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 : mysql date/time converters, part II
Categories : PHP, MySQL, Databases, Date Time Update Picture
Woody Stanford
Date : Feb 20th 2001
Grade : Be the 1st to grade this Code Example
Viewed : 8837
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Woody Stanford
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

Someone wanted to have a converter that took a "human" time and converted it to a MySQL
timestamp. Use the function cvdate() to convert to a UNIX time stamp, then use
timestamp_to_mysql() (fount in the original mysql date/time converters article) to get the
MySQL timestamp value. (Also check out strtotime() for a good english to timestamp
converter!)

<?

//paste this into a file named "cvdate.php3"

//this function supports dash,slash or space delimiting, numeric/english months, and two-
digit years.

function cvdate($s)
{
//this function takes a "human" date and converts it into a UNIX timestamp, zero if error.
// echo("$s<p>");

//what is the delimiting character? (support space, slash, dash)
$delimiter="";
if (strpos($s,"-")>0) $delimiter="-";
if (strpos($s,"/")>0) $delimiter="/";
if (strpos($s," ")>0) $delimiter=" ";

if ($delimiter=="") return 0;

//chop it up
$p1=strpos($s,$delimiter);
$p2=strpos($s,$delimiter,$p1+1);

$x=substr($s,0,$p1);
$y=substr($s,$p1+1,$p2-$p1);
$z=substr($s,$p2+1);

//debug
// echo("$x/$y/$z");

//the last value is always the year, so check it for 2- to 4-digit convertion
if (intval($z)<100)
{
if (intval($z)>69) $z=strval(1900+intval($z)); else $z=strval(2000+intval($z));
}

//intelligently select which converter to use
//(default is M/D/Y, but if the month is "spelled out" then the format is D/M/Y)
if (intval($y)==0)
{
return cvdate_english($x,$y,$z);
}
else
{
return cvdate_numeric($x,$y,$z);
}

}

//just a helper function
function cvdate_english($d,$m,$y)
{
$d2=0; $m2=0; $y2=0;

$d2=intval($d);

$m=strtolower($m);
switch(substr($m,0,3))
{
case "jan": $m2=1; break;
case "feb": $m2=2; break;
case "mar": $m2=3; break;
case "apr": $m2=4; break;
case "may": $m2=5; break;
case "jun": $m2=6; break;
case "jul": $m2=7; break;
case "aug": $m2=8; break;
case "sep": $m2=9; break;
case "oct": $m2=10; break;
case "nov": $m2=11; break;
case "dec": $m2=12; break;
}

$y2=intval($y);

//check for errors!
if (($d2==0)||($m2==0)||($y2==0)) return 0;

//debug
//echo("$m2/$d2/$y2<br>\n");

return mktime(0,0,0,$m2,$d2,$y2);
}

//just a helper function
function cvdate_numeric($m,$d,$y)
{
$d2=0; $m2=0; $y2=0;

$d2=intval($d);
$m2=intval($m);
$y2=intval($y);

//check for errors!
if (($d2==0)||($m2==0)||($y2==0)) return 0;

//debug
//echo("$m2/$d2/$y2<br>\n");

return mktime(0,0,0,$m2,$d2,$y2);
}



?>

Example :
========

<html>

<?

include("datetime.php3");
include("cvdate.php3");

echo("13-sept-99 converted to MySQL timestamp is ".timestamp_to_mysql(cvdate("13-sept-
99"))."<p>\n");

?>

</html>




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
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
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
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
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
PHP Calendar Web App
Categories : PHP, Databases, MySQL, Date Time, Calendar
formating MySQL Timestamp to get a propper Output. related : Timestamp, ereg_replace, mysql, substr
Categories : MySQL, PHP, Date Time, Databases