![]() The “-” operator and AGE() function retrieves the timestamp difference as an interval. In PostgreSQL, the minus operator “-”, the EXTRACT(), and the AGE() functions are used to find the difference between the given timestamps. The output snippet proves that the “EXTRACT()” function succeeds in finding the timestamp difference in seconds. The below-given statement illustrates how to utilize the EXTRACT() function to calculate the timestamp difference in seconds: SELECT emp_name, emp_joining_date,ĮXTRACT(EPOCH FROM (CURRENT_TIMESTAMP, emp_joining_date)) Let’s put this concept into practice for a profound understanding.Įxample: Finding Timestamp Difference in Seconds In Postgres, the EXTRACT() function is used with the collaboration of the EPOCH to get the timestamp difference in seconds: EXTRACT(EPOCH FROM (timestamp_1 - timestamp_2)) How to Find the TIMESTAMPS Difference in Postgres Using EXTRACT() Function? The AGE() function retrieves the timestamp difference as an interval. In this example, the AGE() function is utilized to fetch the difference between the current timestamp and the employee’s joining_date: SELECT emp_name, emp_joining_date, AGE(CURRENT_TIMESTAMP, emp_joining_date) How to Find the TIMESTAMP Difference in Postgres Using AGE() Function?Ī timestamp difference as an INTERVAL can be obtained by passing the given timestamps to the AGE() function: AGE('timestamp_1', 'timestamp_2') Įxample: Finding Timestamp Difference Using AGE() Function The “-” operator successfully retrieves the timestamp difference in INTERVAL. ![]() Suppose we have to subtract the “emp_joining_date” from the CURRENT_TIMESTAMP to get the TIMESTAMP difference as an interval: SELECT emp_name, emp_joining_date, CURRENT_TIMESTAMP - emp_joining_date The return type of the resultant value will be “INTERVAL”.Įxample: Finding Timestamp Difference Using “-” OperatorĪ sample table named “employee_data” has already been created in the database with the following data: Use the below syntax to find the timestamp difference via the “-” operator: TIMESTAMP 'TIMESTAMP_2' - TIMESTAMP 'TIMESTAMP_1' How to Find the TIMESTAMPS Difference in Postgres Using Minus Operator? This post demonstrates how to find timestamp differences in Postgres using the AGE() function, the minus “-” operator, and the EXTRACT() function. While to get the TIMESTAMPS difference in seconds, the EXTRACT() function is executed along with the EPOCH. The “-” operator and AGE() function return the timestamp difference as an interval. In PostgreSQL, the AGE() function, the minus operator “-”, and the EXTRACT() function is used to get the difference between two timestamps.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |