Date convertions

I have a VB6 application which gives me the current date/time i.e Now() as a double.

The figures at the left of the decimal point represent the date and thoes to the right the time.

Is there a function in PHP or MYSQL that will convert the double into the correct date/time.

Regards
johncron

Is there a reason why you simply aren’t using php’s date capabilities to ‘grab/create’ the date you need?

I do not want to rewrite the VB6 application, the double returned from Now() has other data inserted at the decimal point. On the receiving end the PHP will extract this data, reinsert the decimal point and check for the date.

Regards

Am I thinking nobody knows this answer

Show us the php coding you have tried thus far

Can you give an example of the value that PHP sees so that we can see where the date, time and “other data” are?

Hi

I’ve been away for a few days, sorry about not answering sooner.

The other data will start at the decimal point and be an exact number of characters which will be removed prior to converting back to a date.

Without wishing to teach granny to suck eggs; VB /VBA /or VBscript will output this (a question mark is shorthand for print to screen):-

?dbl(now()) - means print to screen the date and time at exactly now and format as a double
this will output 40998.4875347222

conversely

?cdate(40998.4875347222) - means print to screen and format the number as general date/time
this will output ‘30/03/12 11:42:03’

The data I would like to store is the date conversion from the double.

Hope this helps.
johncron

yeah, but in post #1 you say you’re getting this from a VB function called Now()

why are you trying to convert that one in order to store it in mysql?

why not just use the mysql function for the current datetime?

Hi

In the previous post I stated that Microsoft technlogy in VB/VBA/VBscript uses an internal function Now() to produce the current Date/Time.

The current Date/Time is not what I want, what I want is the current Date/Time at the point the VB application output its data. It is not important for you to know the inner workings of what I am doing, only to offer advice (if you wish to) on how to convert the double into the exact date that left the VB application into MySql.

Kind regards
johncron

As Salathe asked

Can you give an example of the value that PHP sees so that we can see where the date, time and “other data” are?

It helps to no end to see what PHP code you have tried.

It is not important for you to know the inner workings of what I am doing, only to offer advice

Actually, sometimes it is. The more information one has relative to a problem, the greater the likelihood an answer will present itself.

No code on this particular item has been written, I was investigating how to store the double in the MySql database to give the desired date/time result.

Basically I am rewriting an IIS/ASP/VB DLL/MS SQLserver web site to WAMP. This item has now become a minor problem as faced with the huge differences between retrieving and maniplating data with these two technologies. What one takes for grated as an easy task in the technology you are familiar with can seem like an insurmountable problem when using another. As I stated previously I do not wish to rewrite the VB Application which functions correctly, I shall probably use a workaround on this as it seems to be dragging on, and there are a myriad of other problems to learn and hopefully solve.

Kind regards
johncron

It looks to me like the “double” is in OLE Automation date format, where the integer part is the number of days since the base date (midnight Dec 30 1899) and the fractional part the fraction of the day (e.g. 6 am is .25).

Given that format, you could use PHP’s date functions or even better its DateTime class. You could take that base date, and add on however many days and seconds the “double” specifies. Look at using things like [url=http://php.net/datetime.add]DateTime::add() or [url=http://php.net/datetime.modify]DateTime::modify(). Once you have a DateTime object representing your chosen date, it is trivial to format it however you like, such as the example you gave, with [url=http://php.net/datetime.format]DateTime::format().

Thanks for your reply.

You are correct in the fact that the double gives a date/time, this was fully explained in an earlier post, however, all answers I have received thus far are completly missing the point which is that the date/time ‘double’ is created elsewhere in the VB application. When received by the website I do not want to alter this date/time in any way, but I do wish to store it in a MySql database. So what I am looking for is either a PHP or MySql function that will convert this ‘double’ into a date/time which has not changed or altered it in any way.

Kind regards
johncron

The description in my previous post laid out the steps you could go through inside a function to go from a “double” represented date/time, to a format that MySQL would be happy to accept – just not laid out in code. There is no single, direct equivalent to cdate() or DateTime.FromOADate() in PHP so you’ll want to write a function for it using the DateTime class as I mentioned above.

Hi

I have had a rethink on this situation and have reached the conclusion that this data can be stored as a string, and when required (not for PHP or MySql use) the oiginal can be reconstituted by insertng a decimal point at position 6 in the string which will give me the desired result.

Thanks for your interest and help on this problem.

Kind regards.
johncron

Okay, that’s nothing like you were asking for. Either way, good luck with whatever it is that you’re doing!