Finally, we used to_timestamp() to convert it back to the original date and time value. We then used extract() to get the Unix timestamp from that date and time value. In this example we used now() to output the current date and time. Result: Current Date/Time | Unix Timestamp | And back again. (Values of type date and time are cast automatically to timestamp or interval, respectively. To_timestamp(extract(epoch from now())) AS "And back again." datetrunc ( field, source, timezone ) source is a value expression of type timestamp, timestamp with time zone, or interval. Here’s another example that further demonstrates how the result reflects the Unix timestamp value provided: SELECTĮxtract(epoch from now()) AS "Unix Timestamp", In this case I passed a specific Unix timestamp value. The operations available on these data types are described in Section 9.9. Here’s a simple example to demonstrate: SELECT to_timestamp(1912995045) PostgreSQL supports the full set of SQL date and time types, shown in Table 8.9. The Unix timestamp (also known as Unix Epoch time, Unix time, or POSIX time) is the number of seconds that have elapsed since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC). In PostgreSQL, we can use the to_timestamp() function to convert a Unix timestamp value to a date/time value. The PostgreSQL formatting functions provide a powerful set of tools for converting various data types (date/time, integer, floating point, numeric) to formatted strings and for converting from formatted strings to specific data types.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |