Datum & Tijd (MySQL): verschil tussen versies

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen
Regel 5: Regel 5:
 
Met <code>from_unixtime()</code> kun je unix tijds-waardes leesbaar formatteren:
 
Met <code>from_unixtime()</code> kun je unix tijds-waardes leesbaar formatteren:
  
<pre>
+
select from_unixtime(1453991397);
elect
+
 
    order_id, order_status, order_total, delivery_last_name,
+
geeft:
    created, from_unixtime(created),
+
 
    modified, from_unixtime(modified),
+
2016-01-28 15:29:57
    product_count from koolborstels.uc_orders where order_status="Completed" order by order_id asc limit 0,10;
 
</pre>
 
  
 
== unix_timestamp() ==
 
== unix_timestamp() ==

Versie van 17 feb 2016 17:40

Tijdens het hacken van een Übercart-Drupal-database kwam ik eindelijk Unix time tegen! En hier zie je hoe ik er chocola van maak.

from_unixtim()

Met from_unixtime() kun je unix tijds-waardes leesbaar formatteren:

select from_unixtime(1453991397);

geeft:

2016-01-28 15:29:57

unix_timestamp()

Met unix_timestamp() converteer je een datum of tijd in een leesbaar formaat terug naar Unix Time:

select unix_timestamp("Oct. 19, 2015");         # Output: 0
select unix_timestamp("2015-10-19");            # Output: 1445205600
select unix_timestamp("2011-07-11 07:50:51");   # Output: 1310363451
select unix_timestamp("2011-07-11");            # Output: 1310335200
select unix_timestamp("2011-07");               # Output: 0

Bronnen