0

In my MySQL database I have one column (text) with about 2000 rows. In each row I have a Julian date (like 2457268 for 2015-09-02).

Looking for a solution to update all rows from Julian to Gregorian.

Any way to do this in either SQL or PHP?

BSMP
  • 4,596
  • 8
  • 33
  • 44
staaland
  • 11
  • 2
  • The code sample you posted seems incomplete. You haven't closed the while loop, incremented (or used) the counter or shown us your jd_to_greg() function. – AllInOne May 19 '15 at 18:25

2 Answers2

0

Have you looked at jdtogregorian() in PHP?

AllInOne
  • 1,450
  • 2
  • 14
  • 32
0

staaland originally posted this answer within their question (in this revision) instead of creating an answer post.


I found the solution myself:

$strSQL = "SELECT * FROM tabel";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");

while($objResult = mysql_fetch_array($objQuery)) {

  $dbDate = $objResult["field1"];
  $id = $objResult["id"];
  $date = jd_to_greg($dbDate);

  mysql_query("UPDATE tabel SET `column1` = '$date' WHERE id=$id");

}
BSMP
  • 4,596
  • 8
  • 33
  • 44