473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Integer date to readable dates

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.

Thanks for any help

Dec 8 '05 #1
6 1943
Trekmp wrote:
numerical format 38694, which is 08/12/2005.


How?

--
E. Dronkert
Dec 8 '05 #2
"Now what is an Excel serial date number? 37477 is a serial date number
and is the number of days since 1-1-1900. 37477 actually translates to
Aug 9, 2002, the date of writing this article."

http://www.codeproject.com/datetime/exceldmy.asp

Dec 8 '05 #3
Sjoerd wrote:
number of days since 1-1-1900


Of course! I missed a decimal, and thought: "Hmm what could it be, number
of days since 1995 somewhere?!"

Unfortunately mktime(0, 0, 0, 1, 38694, 1900) doesn't work (on Windows
anyway), so use an offset:

define('EPOCHINEXCEL', 25568); //01-01-1970 minus 1

function excel2unix($n) {
return mktime(0, 0, 0, 1, $n - EPOCHINEXCEL, 1970);
}

$myexceldate = 38694; //today
echo date('d-m-Y', excel2unix($myexceldate)); //prints 08-12-2005

You may want to extend the function to handle fractions (time of day).

--
E. Dronkert
Dec 8 '05 #4
NC
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

Dec 8 '05 #5
NC wrote:
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".


Oh really!

--
E. Dronkert
Dec 9 '05 #6
Ewoud Dronkert wrote:
NC wrote:
return round(($MSdata - 25569) * 24 * 60 * 60);


Oh really!


Sorry, having never dealt with Exceldates before (in php), I was rather
chuffed with my almost identical solution I posted earlier. But this part
of yours(?) is better because it deals with fractions in one step.

--
E. Dronkert
Dec 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jcs_5920 | last post by:
Hello All, I was reading some of the posts trying to learn about date coding schemes used in old DOS programs with no luck, so I though I'd ask the group for help. These are the HEX values and...
3
by: andrew | last post by:
Hi: I am already using TreeMap to massage records in my export file such that each record has a unique key combination ( LastName + FirstName + Member Key) . Thus I am sorting the records by...
0
by: GMG | last post by:
Background : with XML data islands you can bind data to HTML tags. If you do not provide a DTD it will display the information as is. If you provide a DTD IE will display the data according to its...
4
by: Vladislav Moltchanov | last post by:
I try to use MS Access application as data entry/verification tool in a multi-centre international project, where each centre uses this application for local project management and data...
5
by: mphanke | last post by:
Hi, can somebody tell me how to convert the date from a Paradox .DB to human readable format? I need to write a tool to convert the 4 Bytes representing the date to a human readable format. ...
2
by: TofuTheGreat | last post by:
I'm using "Now.ToOADate" for a record timestamp in a small database app (it's what I want to do so don't try to disuade me ;-D). Anyway. I store the value of Now.ToOADate in a string field in...
11
by: jwf | last post by:
I am writing a NON MFC C++ application (Plug-in for a 3rd party DB system). The application is designed to synchronise data between MS Outlook and the DB system. I am using smart pointers for the...
10
by: Jes | last post by:
Dear all I have a date field on a HTML form where the user is asked to key in dd/mm/yyyy However, when that is written to MySql it is either not accepted or another value is tored in the...
6
by: Jeremy Sanders | last post by:
Hi - I need to add support to a program for dates and times. The built-in Python library seems to be okay for many purposes, but what I would like would be Unix epoch style times (seconds relative...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.