ASP Free Lounge
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherASP Free Lounge

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 14th, 2007, 06:14 AM
adam678 adam678 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 135 adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 33 m 26 sec
Reputation Power: 14
Help reversing a date conversion (maths problem)

Hi

I have a script that converts an excel form to a cvs document. However, there is a problem when converting dates.

If a field is formatted as a date (dd/mm/yyyy) using a cell format, then when it gets converted, the date value is converted to a 5 digit number and I can't figure out what the formula is for getting from a standard dd/mm/yyyy date to a 5 digit number, or how to reverse is.

Here are some examples:

03/07/2003 converts to 37805
10/09/2007 converts to 39335
03/08/2007 converts to 39297

This is the script that does the conversion (its PHP):

http://scripts.ringsworld.com/database-tools/xls2mysql/inc/Excel/reader.php.html

If anyone can explain the maths behind the conversion, but more importantly how to reverse it. Then that would be great!


Thanks!

Last edited by adam678 : September 14th, 2007 at 07:49 AM.

Reply With Quote
  #2  
Old September 14th, 2007, 12:06 PM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,810 Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level)Lauramc User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 20 h 24 m 30 sec
Reputation Power: 1143
In Excel, the five digit number is the number of days since 1/1/1900. Today is 39339 (in Excel).

Your numbers appear to be different (maybe they used 1901, but in any case it's number of days). Using your examples as a benchmark you could set a variable to one of these "known" values. Then calculate the difference between your number and this variable. This will tell you the difference in the number of days. Now convert to datetime and see if you are right. This should verify that these do represent days since some time in the past.

Doing a simple conversion to a datetime will "reverse" this. Since a date can be represented as a decimal, you can convert it to a datetime and get a valid date.
Comments on this post
jmurrayhead agrees: nice, never knew that
__________________
Slarentice (origin:Shadow Wizard of ASP Free) [noun] A slave and apprentice of the Wizard's Circle (specifically of mehere) at ASP Free.
----
If shemzilla takes over, it's best to be on his good side


Reply With Quote
  #3  
Old September 15th, 2007, 10:10 AM
adam678 adam678 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 135 adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level)adam678 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 12 h 33 m 26 sec
Reputation Power: 14
Thanks Lauramc!

I can convert the numbers back to dates using the 'DateAdd' function, i.e.

Code:
Response.write(DateAdd("d", 37805-2, "01/01/1900"))


The date is two days out for some reason, might be something to do with leap years or something....

But yeah, thanks for your help with this, its much appreciated!

Reply With Quote
  #4  
Old September 15th, 2007, 10:54 AM
tctekkie's Avatar
tctekkie tctekkie is offline
Wizardess of Free Spirits
ASP Free Frequenter (2500 - 2999 posts)
 
Join Date: Dec 2004
Location: Michigan
Posts: 2,558 tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)tctekkie User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 13303 Folding Title: Novice Folder
Time spent in forums: 1 Month 2 Days 18 h 29 m 41 sec
Reputation Power: 389
Quote:
Originally Posted by adam678
Thanks Lauramc!

I can convert the numbers back to dates using the 'DateAdd' function, i.e.

Code:
Response.write(DateAdd("d", 37805-2, "01/01/1900"))


The date is two days out for some reason, might be something to do with leap years or something....

But yeah, thanks for your help with this, its much appreciated!


You can also convert the numbers back to dates using formatdatetime()

Code:
Response.write formatdatetime(37805,vbShortDate) & "<BR>"
Response.write formatdatetime(39335,vbShortDate) & "<BR>"
Response.write formatdatetime(39297,vbShortDate) & "<BR>"
__________________
If I've helped you then add to my rep please... Click on the !

Got Milk??


Reply With Quote
Reply

Viewing: ASP Free ForumsOtherASP Free Lounge > Help reversing a date conversion (maths problem)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT