{"id":58,"date":"2009-10-01T17:20:15","date_gmt":"2009-10-02T00:20:15","guid":{"rendered":"http:\/\/shivdev.com\/blog\/2009\/10\/01\/generate-timestamps-in-mysql\/"},"modified":"2009-10-01T17:22:06","modified_gmt":"2009-10-02T00:22:06","slug":"generate-timestamps-in-mysql","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2009\/10\/01\/generate-timestamps-in-mysql\/","title":{"rendered":"Generate Timestamps in MySQL"},"content":{"rendered":"<p>So you want to populate a new column in MySQL with fake dates?<\/p>\n<p>Here&#8217;s how to add a new datetime column in SQL<\/p>\n<blockquote><p> alter table city_new add column mytime datetime;<\/p><\/blockquote>\n<p>Here&#8217;s how to populate it with fake timestamps data<\/p>\n<blockquote><p> update city_new set mytime =  select from_unixtime(<br \/>\nunix_timestamp(&#8216;2009-01-01 01:00:00&#8217;)+floor(rand()*31536000)<br \/>\n);<\/p><\/blockquote>\n<p>Here&#8217;s a more generic formula<\/p>\n<blockquote><p>\nselect from_unixtime(<br \/>\n      unix_timestamp( &#8216;start timestamp&#8217;)<br \/>\n     +floor(rand()* (max interval in seconds) )<br \/>\n);\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>So you want to populate a new column in MySQL with fake dates? Here&#8217;s how to add a new datetime column in SQL alter table city_new add column mytime datetime; Here&#8217;s how to populate it with fake timestamps data update city_new set mytime = select from_unixtime( unix_timestamp(&#8216;2009-01-01 01:00:00&#8217;)+floor(rand()*31536000) ); Here&#8217;s a more generic formula select [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/58"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=58"}],"version-history":[{"count":0,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}