0

I have problem to convert data saved as INTEGER in mysql server to display datetime format.

I have access to sql server view using php.

Date like:

2008-02-29 00:00:00.000

i saved like: 75668 (integer)

How to format

75668

to

date("Y-m-d H:i:s")

? and

date("Y-m-d H:i:s")

to this format (like 75668)?

I see that in sql server it's done like:

cast (a.DATA - 36163 as datetime) DATA_W

How can I format this value using php?

In structure this table I have :

[DATA] [dbo].[T_DATA_TYP] NULL,

this column is create bu custom type. Type declaration is :

CREATE TYPE [dbo].[T_DATA_TYP] FROM [int] NULL
13
  • 3
    What is the relationship between 75668 and 29th February 2008? Is there some kind of formula? Days since a base date? Commented Mar 9, 2016 at 17:50
  • 2
    why are you saving date time as integer data type ?? There is datatype for datetime in mysql database . Commented Mar 9, 2016 at 17:51
  • This is not my database (it's programs db) In sql server column DATA is saved by custom type CREATE TYPE [dbo].[T_DATA_TYP] FROM [int] NULL Commented Mar 9, 2016 at 17:53
  • but 1204243200 is not 75668 Commented Mar 9, 2016 at 17:57
  • In structure this table I have : [DATA] [dbo].[T_DATA_TYP] NULL, this column is create bu custom type. Type declaration is : CREATE TYPE [dbo].[T_DATA_TYP] FROM [int] NULL Commented Mar 9, 2016 at 18:00

2 Answers 2

1

This looks like it's a variant of an MS Excel serialized timestamp, which is a count of the days since 31st December 1899.... if that is the case, then you can convert it to a unix timestamp using a function like:

function ExcelToUnixTimestamp($dateValue = 0)
{
    $excelBaseDate = 25567;

    // Perform conversion
    if ($dateValue >= 1) {
        $utcDays = $dateValue - $excelBaseDate;
        $returnValue = round($utcDays * 86400);
        if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
            $returnValue = (integer) $returnValue;
        }
    } else {
        $hours = round($dateValue * 24);
        $mins = round($dateValue * 1440) - round($hours * 60);
        $secs = round($dateValue * 86400) - round($hours * 3600) - round($mins * 60);
        $returnValue = (integer) gmmktime($hours, $mins, $secs);
    }

    return $returnValue;
}

$weirdTimestamp = 75668;
$unixTimestamp = ExcelToUnixTimestamp($weirdTimestamp - 36163);
echo date('Y-m-d H:i:s', $unixTimestamp);
Sign up to request clarification or add additional context in comments.

1 Comment

There isn't MS Excel serialize timestamp. It's clarion format.
0

This date is in CLARION format.

user this: c#: var xx = new DateTime(1800, 12, 28).AddDays(75668);

in sql: DECLARE @SqlDt DATETIME SET @SqlDt = DateAdd(day, 75668, '1800-12-28') SELECT @SqlDt AS 'SQL Date Time'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.