2

I am exporting info from a database that has field with a birthdate stored as a tick. I need to convert this to a regular date. I can either do it in the SQL statement (if there is a way?) or convert it into excel since I will import my data there?

EDIT: Sorry, not very familiar with ticks, so wasn't sure what info to include. The database is postgreSQL. Just putting it in a format mm/dd/yyyy is fine (excel should understand that).

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
rsp
  • 811
  • 2
  • 12
  • 32

1 Answers1

3

You need to convert the .NET ticks to UNIX Epoch and then to a postgreSQL timestamp.

to_timestamp((("date" - 621355968000000000) / 10000000))

This code will work with version 9 and above

Wize
  • 1,040
  • 9
  • 20
  • This expression loose milliseconds. Compare: `SELECT to_timestamp(((636892826050036451 - 621355968000000000) / 10000000.0)) as with_milliseconds, to_timestamp(((636892826050036451 - 621355968000000000) / 10000000)) as without_milliseconds` – Maxim Apr 23 '19 at 12:05