We have a table named “sale” in our database. The output shows that the specified interval has been added to the current date successfully.Įxample #7: How to Add Date/Time to a Table’s Column in PostgreSQL? Next, we utilized the “+” operator with the INTERVAL data type to add an interval to the current date: In the above query firstly, we utilized the CURRENT_DATE function to get the current date. Let’s run the below statement to add an interval into the current date: SELECT CURRENT_DATE + INTERVAL '10 Days 1 Hour 15 Minutes' This is how you can add/subtract a date or time in a specific date, time.Įxample #6: How to Add Date/Time Into a Current Date/Time in PostgreSQL? In this example, we will add five hours, 12 minutes to the specified date/time: SELECT DATE '' + INTERVAL '2 HOURS 12 MINUTES' We can also add time to the given date/time by employing the interval data type. The output proved that using INTERVAL data type, you can add/subtract months to the given date.Įxample #5: How to Add Time Into a Date/Time in PostgreSQL? Let’s run the below statement to add two months to the given date: SELECT DATE '' + INTERVAL '2 MONTHS' We will use the INTERVAL data type to add three weeks to the given date: SELECT DATE '' + INTERVAL '3 WEEKS' įrom the output, you can observe that three weeks have been added to the given date.Įxample #4: How to Add Months Into a Date/Time in PostgreSQL? Three days have been subtracted from the specified date.Įxample #3: How to Add Weeks Into a Date/Time in PostgreSQL? Let’s subtract three days from “” using “-” operator: SELECT DATE '' - INT '3' Three days have been added to the given date successfully.Įxample #2: How to Subtract Days From a Date/Time in PostgreSQL? For this purpose, we utilize + operator as follows: SELECT DATE '' + INT '3' Suppose we have to add 3 days into the date “”. In Postgres, the + or - operators can be used to add or subtract an interval to a Date/time.Įxample #1: How to Add Days Into a Date/Time in PostgreSQL? How to Add Interval to Datetime in PostgreSQL? This post is going to assist you in this regard with the help of practical examples. ![]() Now you must be wondering how to achieve such functionality in PostgreSQL. ![]() However, PostgreSQL doesn’t provide any equivalent function. ![]() Similarly, MySQL and MariaDB have DATE_ADD() and ADDDATE() functions to add an interval to a date/time, and SQLite provides a DATE() function that can be used to add an interval to a date/time. SQL provides a DATEADD() function that adds a date or time interval to a specific date and returns the updated date.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |