Una possibile soluzione sarebbe quella di avere una costante a portata di mano corrispondente ai secondi in un certo numero di anni (preferibilmente un multiplo di 4). È possibile aggiungere questa costante, tradurre il tempo e quindi sottrarre il numero di anni scelti.
Esempio: scegliere 40 anni.
determinare la costante:
MySQL [files]> select adddate(from_unixtime(0), interval 40 year);
+---------------------------------------------+
| adddate(from_unixtime(0), interval 40 year) |
+---------------------------------------------+
| 2010-01-01 01:00:00 |
+---------------------------------------------+
1 row in set (0.09 sec)
MySQL [files]> select unix_timestamp(adddate(from_unixtime(0), interval 40 year));
+-------------------------------------------------------------+
| unix_timestamp(adddate(from_unixtime(0), interval 40 year)) |
+-------------------------------------------------------------+
| 1262304000 |
+-------------------------------------------------------------+
1 row in set (0.09 sec)
Ora è possibile ogni unix timestamp x
tra il 1930 e 20xx e usarlo.
select subdate(from_unixtime(x+1262304000), interval 40 year);
Con il vostro esempio -769338000
, si ottiene
MySQL [files]> select subdate(from_unixtime(-769338000+1262304000), interval 40 year);
+-----------------------------------------------------------------+
| subdate(from_unixtime(-769338000+1262304000), interval 40 year) |
+-----------------------------------------------------------------+
| 1945-08-15 17:00:00 |
+-----------------------------------------------------------------+
1 row in set (0.09 sec)
Usando questo, grazie :) –