Ok, new question...

I need to get data from one mysql row, set it as $ad

The following code will convert it to readable date format.

<?php

function adConvert ($ad) {
  $seconds_ad = $ad / (10000000);
   //86400 -- seconds in 1 day
   $unix = ((1970-1601) * 365 - 3 + round((1970-1601)/4) ) * 86400;

   $timestamp = $seconds_ad - $unix; 
   $normalDate = date("F d, Y", $timestamp);

      return $normalDate;
}
 echo adConvert($ad);
?>

Now i need to insert it in a new row.

Get value from row1 convert insert in row2
Hé hé, i only have dificoult questions...

Now i use a form, but i need a code that does it automaticly:

<html>
<head>
<?php
$ad = $_POST['keyword'];
 echo "<title>" . adConvert($ad) . "</title>";
 ?>
</head>
<body>
<?php

function adConvert ($ad) {
  $seconds_ad = $ad / (10000000);
   //86400 -- seconds in 1 day
   $unix = ((1970-1601) * 365 - 3 + round((1970-1601)/4) ) * 86400;

   $timestamp = $seconds_ad - $unix; 
   $normalDate = date("F d, Y", $timestamp);

      return $normalDate;
}
 echo adConvert($ad);
?>
Member Avatar for diafol

YUK! There must be a better way than this to convert your date. In what format is $ad? Looks like [seconds * 10000000]. I just don't get that.

Anyway, you want to get a value from DB, send it through your function and update the same record or just create a new record in a different table?
Inserting to the same table deosn't really make sense.

This is waht i get from LDAP: 130282300307020478
And this is what i get afer convert it with this script: November 06, 2013

There must be a way to add this script.
Like my other question:
If lastlogh has 130282300307020478 convert to November 06, 2013 and insert in to lastlogon

Member Avatar for diafol

Ah, OK now I get it it's ldap/active dir format...

$seconds_ad = (int) ($ad / 10000000);
$u = $seconds_ad - 11644473600;
echo date("F d, Y", $u);

... worked for me. The big int refers to win(1600-1-1) - unix(1970-1-1) in seconds.

For the conversion, you have a choice. Either copy the ldap date as is and convert in php on the fly when outputting the data OR convert from ldap into mysql (so store conversion in mysql).

Do NOT store dates as "F d, Y" format!! Store then as timestamps or datetimes. I usually go with timestamps as they are generally easier to deal with.

function ad2uts($ad)
{
    $seconds_ad = (int) ($ad / 10000000);
    $u = $seconds_ad - 11644473600;
    return $u;
}

From LDAP: $ad

For mysql...

"INSERT INTO table SET lastlogon = " . ad2uts($ad);

...whatever...

Yu da men...
thanks to you it works now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.