{"id":2565,"date":"2025-03-25T08:01:09","date_gmt":"2025-03-25T01:01:09","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=2565"},"modified":"2025-04-02T15:33:52","modified_gmt":"2025-04-02T08:33:52","slug":"postgresql-age","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/","title":{"rendered":"PostgreSQL AGE Function"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you&#8217;ll learn how to calculate the difference between two dates using the PostgreSQL <code>AGE()<\/code> function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"postgresql-age-function-overview\" id='postgresql-age-function-overview'>PostgreSQL AGE Function Overview <a href=\"#postgresql-age-function-overview\" class=\"anchor\" id=\"postgresql-age-function-overview\" title=\"Anchor for PostgreSQL AGE Function Overview\">#<\/a><\/h2>\n\n\n\n<p>The&nbsp;<code>AGE()<\/code>&nbsp;function allows you to calculate ages, such as years of service of employees.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"syntax\" id='syntax'>Syntax <a href=\"#syntax\" class=\"anchor\" id=\"syntax\" title=\"Anchor for Syntax\">#<\/a><\/h3>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">AGE(end_date, start_date)<\/code><\/span><\/pre>\n\n\n<p>The&nbsp;<code>AGE<\/code>&nbsp;function has two parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>end_date<\/code>: the more recent timestamp.<\/li>\n\n\n\n<li><code>start_date<\/code>: the older timestamp.<\/li>\n<\/ul>\n\n\n\n<p>The&nbsp;<code>AGE()<\/code>&nbsp;function has another variant that accepts one argument:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">AGE(start_date)<\/code><\/span><\/pre>\n\n\n<p>If you pass one parameter (<code>start_date<\/code>) to the&nbsp;<code>AGE<\/code>&nbsp;function, it will compare the&nbsp;<code>start_date<\/code>&nbsp;with the current date.<\/p>\n\n\n\n<p>The\u00a0<code>AGE()<\/code>\u00a0function returns a value of the\u00a0<code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-interval-data-type\/\">INTERVAL<\/a><\/code>\u00a0data type, representing the difference between the\u00a0<code>end_date<\/code>\u00a0and\u00a0<code>start_date<\/code>\u00a0in years, months, and days.<\/p>\n\n\n\n<p>The&nbsp;<code>AGE()<\/code>&nbsp;function returns&nbsp;<code>NULL<\/code>&nbsp;if the&nbsp;<code>start_date<\/code>&nbsp;or&nbsp;<code>end_date<\/code>&nbsp;argument is&nbsp;<code>NULL<\/code>.<\/p>\n\n\n\n<p class=\"note\">Note that the&nbsp;<code>AGE()<\/code>&nbsp;function correctly handles leap years, ensuring proper date calculations.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"calculating-the-age-between-two-dates\" id='calculating-the-age-between-two-dates'>Calculating the Age Between Two Dates <a href=\"#calculating-the-age-between-two-dates\" class=\"anchor\" id=\"calculating-the-age-between-two-dates\" title=\"Anchor for Calculating the Age Between Two Dates\">#<\/a><\/h2>\n\n\n\n<p>The following statement uses the&nbsp;<code>AGE()<\/code>&nbsp;function to calculate the difference between January 1, 2000, and March 22, 2025:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  AGE (<span class=\"hljs-string\">'2025-03-22'<\/span>, <span class=\"hljs-string\">'2000-01-01'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIEFHRSAoJzIwMjUtMDMtMjInLCAnMjAwMC0wMS0wMScpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">           age\n---------------------\n25 years 2 mons 21 days<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"calculating-the-age-from-a-given-date\" id='calculating-the-age-from-a-given-date'>Calculating the Age From a Given Date <a href=\"#calculating-the-age-from-a-given-date\" class=\"anchor\" id=\"calculating-the-age-from-a-given-date\" title=\"Anchor for Calculating the Age From a Given Date\">#<\/a><\/h2>\n\n\n\n<p>The following statement uses the&nbsp;<code>AGE()<\/code>&nbsp;function to calculate the difference between January 1, 2000, and today:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  AGE (<span class=\"hljs-type\">TIMESTAMP<\/span> <span class=\"hljs-string\">'2000-01-01'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIEFHRSAoVElNRVNUQU1QICcyMDAwLTAxLTAxJyk7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Assuming that we run this function on March 25, 2025, the output will look like the following:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">           age\n-------------------------\n 25 years 2 mons 24 days<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id=\"calculating-age-with-leap-years\" id='calculating-age-with-leap-years'>Calculating Age With Leap Years <a href=\"#calculating-age-with-leap-years\" class=\"anchor\" id=\"calculating-age-with-leap-years\" title=\"Anchor for Calculating Age With Leap Years\">#<\/a><\/h2>\n\n\n\n<p>The following example uses the&nbsp;<code>AGE()<\/code>&nbsp;function with leap years:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  AGE (<span class=\"hljs-string\">'2025-03-01'<\/span>, <span class=\"hljs-string\">'2020-02-29'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIEFHRSAoJzIwMjUtMDMtMDEnLCAnMjAyMC0wMi0yOScpOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">      age\n---------------------\n5 years 1 day<\/code><\/span><\/pre>\n\n\n<p>The output indicates the&nbsp;<code>AGE()<\/code>&nbsp;function correctly handles the leap years.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"calculating-years-of-service\" id='calculating-years-of-service'>Calculating Years of Service <a href=\"#calculating-years-of-service\" class=\"anchor\" id=\"calculating-years-of-service\" title=\"Anchor for Calculating Years of Service\">#<\/a><\/h2>\n\n\n\n<p>First, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-create-table\/\">create a\u00a0table<\/a> called <code>employees<\/code> to store employee data:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> employees (\n  id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\n  <span class=\"hljs-type\">name<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">255<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\n  joined_date <span class=\"hljs-type\">DATE<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=Q1JFQVRFIFRBQkxFIGVtcGxveWVlcyAoIGlkIElOVCBHRU5FUkFURUQgQUxXQVlTIEFTIElERU5USVRZIFBSSU1BUlkgS0VZLCBuYW1lIFZBUkNIQVIoMjU1KSBOT1QgTlVMTCwgam9pbmVkX2RhdGUgREFURSBOT1QgTlVMTCApOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Second, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-insert\/\">insert some rows<\/a> into the\u00a0<code>employees<\/code>\u00a0table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\n  employees (<span class=\"hljs-type\">name<\/span>, joined_date)\n<span class=\"hljs-keyword\">VALUES<\/span>\n  (<span class=\"hljs-string\">'Alex'<\/span>, <span class=\"hljs-string\">'2022-04-10'<\/span>),\n  (<span class=\"hljs-string\">'John'<\/span>, <span class=\"hljs-string\">'2025-03-02'<\/span>),\n  (<span class=\"hljs-string\">'Joe'<\/span>, <span class=\"hljs-string\">'2023-01-15'<\/span>),\n  (<span class=\"hljs-string\">'David'<\/span>, <span class=\"hljs-string\">'2020-11-30'<\/span>),\n  (<span class=\"hljs-string\">'Eve'<\/span>, <span class=\"hljs-string\">'2022-08-05'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=SU5TRVJUIElOVE8gZW1wbG95ZWVzIChuYW1lLCBqb2luZWRfZGF0ZSkgVkFMVUVTICgnQWxleCcsICcyMDIyLTA0LTEwJyksICgnSm9obicsICcyMDI1LTAzLTAyJyksICgnSm9lJywgJzIwMjMtMDEtMTUnKSwgKCdEYXZpZCcsICcyMDIwLTExLTMwJyksICgnRXZlJywgJzIwMjItMDgtMDUnKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Third, use the&nbsp;<code>AGE()<\/code>&nbsp;function to calculate the service duration and year of service to the current date (till midnight):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\n  <span class=\"hljs-type\">name<\/span>,\n  joined_date,\n  AGE (joined_date) <span class=\"hljs-keyword\">AS<\/span> service_duration,\n  EXTRACT(\n    <span class=\"hljs-type\">YEAR<\/span>\n    <span class=\"hljs-keyword\">FROM<\/span>\n      AGE (joined_date)\n  ) <span class=\"hljs-keyword\">AS<\/span> years_of_service\n<span class=\"hljs-keyword\">FROM<\/span>\n  employees;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?q=U0VMRUNUIG5hbWUsIGpvaW5lZF9kYXRlLCBBR0UgKGpvaW5lZF9kYXRlKSBBUyBzZXJ2aWNlX2R1cmF0aW9uLCBFWFRSQUNUKCBZRUFSIEZST00gQUdFIChqb2luZWRfZGF0ZSkgKSBBUyB5ZWFyc19vZl9zZXJ2aWNlIEZST00gZW1wbG95ZWVzOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> name  | joined_date |    service_duration     | years_of_service\n-------+-------------+-------------------------+------------------\n Alex  | 2022-04-10  | 2 years 11 mons 15 days |                2\n John  | 2025-03-02  | 23 days                 |                0\n Joe   | 2023-01-15  | 2 years 2 mons 10 days  |                2\n David | 2020-11-30  | 4 years 3 mons 25 days  |                4\n Eve   | 2022-08-05  | 2 years 7 mons 20 days  |                2<\/code><\/span><\/pre>\n\n\n<p>Note that the service duration and year of service depend on when you run the query.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the&nbsp;<code>AGE()<\/code>&nbsp;function to calculate the interval difference in years, months, and days.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"2565\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL AGE Function\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"2565\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL AGE Function\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2440,"menu_order":13,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2565","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL AGE Function<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL AGE Function\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-02T08:33:52+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/postgresql-age\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/postgresql-age\\\/\",\"name\":\"PostgreSQL AGE Function\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2025-03-25T01:01:09+00:00\",\"dateModified\":\"2025-04-02T08:33:52+00:00\",\"description\":\"In this tutorial, you'll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/postgresql-age\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/postgresql-age\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/postgresql-age\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Date Functions\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-date-functions\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL AGE Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL AGE Function","description":"In this tutorial, you'll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL AGE Function","og_description":"In this tutorial, you'll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-04-02T08:33:52+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/","url":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/","name":"PostgreSQL AGE Function","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2025-03-25T01:01:09+00:00","dateModified":"2025-04-02T08:33:52+00:00","description":"In this tutorial, you'll learn how to calculate the difference between two dates using the PostgreSQL\u00a0AGE()\u00a0function.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/postgresql-age\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Date Functions","item":"https:\/\/www.pgtutorial.com\/postgresql-date-functions\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL AGE Function"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=2565"}],"version-history":[{"count":8,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2565\/revisions"}],"predecessor-version":[{"id":2584,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2565\/revisions\/2584"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/2440"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=2565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}