473,789 Members | 3,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1963
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('EPOCHIN EXCEL', 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($mye xceldate)); //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
3589
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 corresponding dates I am using. If anyone can help me figure out the encode / decode method I would really appreciate it. Date only, no time stored. 9C07 0B00 = 01-15-80 9D07 0B00 = 01-16-80 BB07 0B00 = 02-15-80
3
14614
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 the unique key. I also have a Date String Field in my record ( ie "30-Apr-2005" ). I want to create a unique key combination of ( LastName + FirstName + Member Key + Date). Can you please tell me what are the steps I need to do to sort the Date
0
1339
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 datatype. The most significant is dates, by providing the date in the proper XML format IE will display the date in a nice readable format. But being in Ausrtralia I am expecting my date format to be displayed like so : dd/mm/yy It is...
4
4003
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 collection. Regularly the data are being unloaded , confidential information is masked, and modified data are being sent to me for pooling and analysis. One serious problem has emmerged recently: there are some centres where local format for dates is...
5
2787
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. Thanks for your help,
2
7070
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 the database (16 character field on a SQL server to be exact). Is there a way of converting the text value from that field back into a readable date/time? For example if a date is stored in the 16 character field as the OLE Automation format...
11
5276
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 development which is fine and sysnchronisation back and forth is working as expected. The problem I am having is with the DATE type (implemented using an 8-byte floating-point number. Days are represented by whole number increments starting with...
10
2548
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 database. Is there any way to change value of this field back to yyyymmdd format as accepted correctly in sql. ? The change should preferably be when user click on submit.
6
2431
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 to some date), covering a large period from the past to the future. What would be nice would be a library which can take floating point seconds from an epoch. Does anyone know of a library which can convert from human style dates and times to a...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.