SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a reason why you simply aren't using php's date capabilities to 'grab/create' the date you need?

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by litebearer View Post
    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

  4. #4
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johncron View Post
    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

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Show us the php coding you have tried thus far

  6. #6
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    Can you give an example of the value that PHP sees so that we can see where the date, time and "other data" are?
    Salathe
    Software Developer and PHP Manual Author.

  7. #7
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    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

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,020
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by johncron View Post
    The data I would like to store is the date conversion from the double.
    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?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    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

  10. #10
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by litebearer View Post
    As Salathe asked

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


    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

  12. #12
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    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 DateTime::add() or 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 DateTime::format().
    Salathe
    Software Developer and PHP Manual Author.

  13. #13
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    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 DateTime::add() or 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 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

  14. #14
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johncron View Post
    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.
    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.
    Salathe
    Software Developer and PHP Manual Author.

  15. #15
    SitePoint Member
    Join Date
    Jan 2012
    Location
    UK, Hampshire
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    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

  16. #16
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    55 Post(s)
    Tagged
    0 Thread(s)
    Okay, that's nothing like you were asking for. Either way, good luck with whatever it is that you're doing!
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •