Reply to Re: Integer date to readable dates

Your name:

Reply:


Posted by NC on 12/09/05 01:28

Trekmp wrote:
>
> I currently work in ASP and am in the process of moving some
> application across to PHP. At present I store dates in a database
> in numerical format 38694, which is 08/12/2005. In ASP its very
> easy to convert this value back into a date, but I cannot find a way
> to do this in PHP.

First of all, you should have ways of converting the numerical
presentation into a human-readable date on the database level. In SQL
Server, you can use the CONVERT() function for that.

If for whatever reason this is not feasible (although I can't imagine
why), you must remember that PHP relies on Unix system libraries to
work with dates. So PHP is not well-suited to handling dates preceding
January 1, 1970. Assuming all your dates are after January 1, 1970,
here is a quick fix:

function MStoUnix ($MSdate) {
return round(($MSdata - 25569) * 24 * 60 * 60);
}

This function converts a Microsoft "timestamp" (number of days since
January 1, 1900) into a Unix timestamp (number of seconds since January
1, 1970). Then you can format the resulting timestamp using the date()
function. For example, this snippet:

echo date('Y-m-d', MStoUnix(38694));

would output "2005-12-08".

Cheers,
NC

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация