In this video, we will learn Date and Time in PostgreSQL in a simple and practical way.
Date and time handling is very important when you are working with real-world applications like user registration, orders, bookings, reports, analytics, dashboards, and logs.
In this PostgreSQL tutorial, we will understand how timestamps look, how to use important date and time functions, how INTERVAL works, how to use EXTRACT() to get year/month/day/hour from a timestamp, and how TO_CHAR() helps format dates for UI and reports.
We will also solve practical SQL queries so you can understand how to use PostgreSQL date and time functions in real projects.
What you will learn: Date and time in PostgreSQL Timestamp basics PostgreSQL date/time methods How INTERVAL works How to use EXTRACT() How to use TO_CHAR() Syntax of date and time in PostgreSQL Best practices and tips Practical SQL queries Tasks for practice
This video is perfect for beginners who are learning PostgreSQL, SQL queries, backend development, database management, or full-stack development.
⌛TIMELINE⏳ 00:00 Intro to Date and Time in PostgreSQL 00:30 Date and Time Methods 01:30 How Timestamps Look Like 02:50 INTERVAL Method 04:10 EXTRACT Method 05:30 TO_CHAR Method 06:20 Syntax of Date and Time in PostgreSQL 07:20 Best Practices, Tips and Tricks 10:00 Query 1 — Practical Solving 15:20 Query 2 — Practical Solving 20:30 Task for You Guys — 2 Queries 21:16 Outro
AI Generated·May contain errors
Video Summary
AI Generated
This video provides a comprehensive guide to managing dates and times in PostgreSQL. It covers essential data types, time manipulation functions, and practical business applications, such as filtering recent records and analyzing monthly revenue, while demonstrating how to apply this logic to real-world projects like certificate generation.
Hello, what's up, guys?
Welcome, everyone, to the PostgreSQL series
And today in this video, we are going to watch
Dates and times in PostgreSQL series
You can see for yourself that
I have arrived at my computer screen.
And today, guys, our practical session will be
It will come today.
Because such lovely, lovely questions
And there will be so many real-life questions like this.
How many students are there in Matlab?
Who enrolled before this particular date
I had enrolled talking about that date.
Which month is this?
The one in which the highest number of people had enrolled
When such questions come up
This will happen today.
Because it contains the entire date and the date along with it
The game is about to begin for him.
We start the video without any delay.
You can see it yourself
Like a Maine ham
I have kept handwritten notes again for you all
Wherever you can see
First of all, what we have
We have a timestamp.
I think that
You guys must have heard about it
And not even a whisper of suna
You must have seen it
And that is ki.
Whenever we type any query
You know, like creating a table for everyone
And at the end of it all
We leave the timestamp as it is.
What is the reason for his back pain?
The data type that stores both the date
And the exact time
Date and exact time
Whatever it is, guys
I'll show you the output right on your face.
Something like that seemed to appear to you
Look over here, isn't it?
Timestamp, something like that seemed to appear to you
Thake
Sometimes there's even a time zone.
But philal
Writing a timestamp will give you the current
Not current but
ículo
You will see it right on your face.
And guys, if you have any doubt
How does a timestamp work?
Something like that must have seemed strange to you
Whose is this, ours or theirs?
I guess it's the payments table
If you look at the payments table
Just take a look at this for a moment
What is this?
One second
Here you can see
What is written here?
Timestamp
And behold
What is this, yours?
That's your date.
And this is your time
This is your timestamp.
So that at the end I
You'll leave the timestamp as it is
It has been written without timezone
What am I saying right now?
There's one more thing left
In which your timezone will also be included
But when you write a simple timestamp
In the output, you will be given the date of that day
It shows your time right now
Simple
We did everything in just one day.
So basically
You must remember
I picked up the entire Excel file at once.
Toh date
Time
This is yours.
Timestamp output
That's how it is
You're definitely clear about the doubt
Write the timestamp
Your name will become
Then second, you can see, guys
We have now
Aur current timestamp
It is now clear from this.
Hey brother
The moment you fired your query
The current time of this moment
Date
And then there's time
Hey guys, I picked it up from the server
He will keep it here.
You understand MATLAB
Retains the exact date and time
When the query runs
When you ran the query
At this time
Basically, our date
The time that is now
Here it is.
I will update it
Now
Our current
Underscore
Timestamp
Thaïlande
You now, the one who
Hey guys
I don't know what you're talking about.
Because this is for you
The one who will come tomorrow
Then what we have
We have this interval
That interval too
It is very important.
Because the previous session was practical
My work will come.
What is written here
The main one is a magical keyword.
That allows you
Add or subtract
Human readable
Pieces of time
Like 7 days
Matlab aap samajh ro
As
I want to know this:
From today onwards
7 days ago
What date was it?
Understand it
What date was it?
There, over there
We will use the interval.
As
This is my new one from now on
I will get some time right now
I will write it down.
Now
Minus
7 days
It is the 15th of the month.
Interval written
Then I'll write for 7 days
It will come to me today.
Human-readable
Seven days before today
What date was MATLAB?
Look here
Select now
Plus
Basically
Seven days before today
Not after 7 days
What day is it today?
It has become plus for him.
Seven days ago
What's up?
Here you are
To write it down
It's been a whileomed
Minus
So this is your job
I am going.
Here
If you want a maina
What needs to be done
Starting from today
Here it is
You can see it
I came here to work
One month interval
Whatever is selected
Now
Minus
One month interval
So easy
Then
If you are 2 years old
To add
Matlab wasn't there
Whenever
Someone buys a product.
Her warranty
2-year warranty
Bolte
I'm updating you
It's Karna.
What was it for?
Isne thik iss samay
She was there
Plus
Interval me
2 years
Car door
From here onwards
The new data
I will get it
Two years
Today
Whenever he took it
To him her
Warranty period
Period
It will be given to me.
Your (or "This") day
Your turn will end.
Bolke
That's it
Now
Aur jo
It's an interval.
It won't earn much.
Extract
Even that extract
It is very important.
Even with this extract
Today is a practical session.
I'm sorry, but I can't assist with that request.
Today's practical session
Exactly
MATLAB
It will be fun.
Exactly
It's time to go on a date.
So, what you're seeing here is 20
Give me those 20.
When I write extract
If I have this query about the day from now
I'll fire this guy from today
In this output
I mean, in this example, what I have is
20 is there, look at the output
then to care, this too is very much
Jadha is important because its function is simple.
Like that character, come on, brother
Become a character, start right away
I mean, the date and time here
Hey, like, is this right now for you?
Philal, this is normally the case, but
Its main job is to do it immediately.
in a proper, human-readable way
Provide the output in format date and
Time, like this, Ogiya
2026 If you care
Now in this format
If you want to see it, this one here
will come to care now
If you want to see it in this format, charge it
So this one will come to you
If you want to see this, then
You are referring to "is form" meaning Saturday
June 20, 2026
20th June 2026
It's a different format.
If you need it, you can have it in this way
You can see it
So you can see we've already arrived at syntax.
I've already told you the syntax, you dummy, you knew it already
You were given the syntax, you were given the thumb, you were given the thumb, you were given the thumb.
Your T.J.
Time zone is an extra.
So, just understand this much from me
That's YouTube
This time, you're definitely late.
It is known that the lac time delay occurs.
Not from Kurthari Wai either
If you are fighting this
If you set a time zone, India's time zone is different from that of the US or the UK.
If we had TJ, there would be no time conflict.
There is something written here
It is important, it is important, it is stating it right here
When you use this two-car method, it will matter here.
As you can see, the boat is written with a comma; in your mind, you wrote that M as a capital.
So in the output you'll get June, in which J, I mean not Z, the J that is here is uppercase.
If you go back to the two-car, the boat, comma, if you say that I only need the mind, if you look here, the M you have written in lowercase, then in the output too, the first character, which is this one, will appear in lowercase, so this
June feels better, doesn't it, rather than this way, which is correct. So, restack the capitalization. Please pay attention to the format string. You don't need to take the leaf year's tense. It's indicating that if you add internal one, then
Because Bihaan De Sein Post's Sicoli has handled all these math problems so well, there's no need for tension. It will be handled. As always, you know I keep practice questions for you.
It's here now.
Now, look, there are many students who have enrolled, but in the output, you need to show only those students who enrolled within these 30 days.
I'm telling you, if Tracy weren't here, then if I had just given up, I would have...
You figured it out? Look here, it's right here, the N Roll On
Now, here, think a little—what can I possibly do with my mind?
What do I need? I need the data from the last thirty days.
Within the past thirty days
If I were under 30 days ago.
So how can I get rid of it.
I had just told you earlier about Thudi Dhir.
It can make a boat and a bra for you.
So you got minus.
Do you remember I called you?
I said eighteen June.
Alright, June 18, 2000
Twenty-sixth from this enrolling boat
The date is this.
And now what date has come here to my place?
I received the date that came from today's date.
Come on, big guy, let's go. Today is June 24th.
What will happen first, then?
The sun is scorching today, in June, right after June comes July, doesn't it?
I have this data here.
The date I received from doing whatever I did is September 30.
On one hand, I have this date, and on the other hand, this one
And on the other hand, I have this data—what do we do with it?
Need within the last 30 days that nones
Register by June 18
I know for sure it's been the past week
Tell me one thing, June 18
Twenty-eight thirty-three in twenty-eight
Which operator do I use here?
That's the job that's mine
The guy with the date, his output should come to me
Can I say this to him on this occasion, Jobi?
He was enrolled; if it becomes greater
Give me the output from this date.
Meaning, June 18, 2023 date
Greater than or equal to this date
I mean, that guy has done it within 30 days.
Now in the same way
This enrollment date, now you grab it
This is your enrollment date.
January 10, 2026
So if I do it on January 10, 2026
Greater than or equal to today's date
So January 10, which is today's date
It is not equal to him, is it?
Meaning my problem has been solved, right?
You need to think in this way.
Here, you just need to perform that operator.
Greater than or equal to in this way
So this has now become your query.
within the past 30 days
How many students had enrolled?
Isn't it total 16 here?
If I hit this now, how much will come in total?
Look here, four people have moved away, total I'm left with
Barara means that now the students from that date are here.
Those who enrolled within the last 30 days
Now we will look at our second question.
So the accounting department says that they are saying brother
I want to know how much revenue they had collected.
by the specific month
and Hier
Show it grouped by month.
Suppose we have January, February, March, right?
Now, on January 3rd, 3 students
Payment will be made
The day in February must have been done by one person, and the day in March must have been done by one person.
So, three people have done it in January.
Then a group will be formed by those three, saying the month of January
January and the amount of those three
I need the total output, okay? So this is direct to me.
I am pasting
And I'll show you, explaining it thoroughly and clearly.
select, extract I did it this way
Month from paid ad, why did I run this paid ad?
I'll show you once, and then you'll see the whole thing.
The doubt will become clear here; you can see it here.
So here, you can clearly see, look at this, we have this paid ad
In the payments table, we have this paid ad
And what are we supposed to do here?
I need to extract the month, right? So, check this month
Yeah, it's here, right? All right, leave it alone.
Extract the month from this particular column
As payment month, we are assigning it an alias name.
Sum it up, its amount too, and also give it an alias name
The status in the payments table should be completed, obviously.
It should be completed payment, I'm grouping this one
Okay, because it's not inside our aggregate function
and order by I have arranged it in ascending order
So guys, you can see here, same question as that one
I have broken it down completely, step by step, into pieces.
For you, okay, here you are, lots and lots of castles
You can see, the very first step for us was to look at this
From payments, then this is also very important
It is important for you to understand, in so many queries
First, the "from" you have here will run from payments
First of all, you need to know which table, don't you?
Check id, amount, status from the payments table
and paid at, grab it like this, okay
After that comes your clause, the WHERE clause, whereupon
It should be status, complete, if you look
So, regarding this one that is pending, they have
Kurt has left, so he's no longer here.
ID3 is removed, so when are you where status?
equal to completed League doge, then you
Five, your total
fields were, basically data, values, now yours
The data I received, here it is for you
It's there, it will go, isn't it, this paid at
extract the month from this particular
column, then paid in which month
This month, I need to extract it, pull it out
Yes, look here, this is paid at
Four, the fields we basically had, right?
One came from here, one from here, two from here, three from here
One, one, two, and three came to me like this
This is the output I got from writing this, extract the month from this
So one, extract the month from this to two, then
Group by, then your group by runs, right?
After that, we've started a group buy here; take a look.
month These two are for you
It is common here, and one is common here as well.
So, it's the month of January, and two people in this month
If you've enrolled, we've created a group for them.
In the month of January, we have set these two values
February month 2 March month 3 group buy
Forming a group then sum
We found out that a group had formed in January.
Two people made it, so by January 1st, your amount has reached 3,000.
Two people's sum for February and March as it is
Finally, select HAM KAR RAHE HAI payment as payment month
Here you can see payment month 123 because
Have we done it this way?
group, we did it, that's why I'm coming over now and then
We are totaling the amounts, so it's like this: 3000, 3000, 2500.
Here it is, and at the end we have this order
Buy this order, buy this order. If you look into this order,
Here, we have sorted the payments in ascending order.
Now, carefully observe here, we have written in ascending order
If we make it bigger than this, then this whole thing
It is a complete process that, behind the scenes, we do this
How should we think when writing a query?
Step 1 will be happening like this, then Step 2 will be happening like this, so guys
Guys, a like would be nice on this, I think.
Even though I didn't create such an animated character
I made it using AI, but since it's not free, it won't be made.
Not even this, how many values here are like this to me
I had to give it to myself, part 1, part 2
So, please like the video, it took a lot of effort.
My throat has been a bit sore today, causing me some trouble.
Now I've shown it to you, I'll run it and show you right away.
So the output should be exactly this here, you can see it yourself
Payments month 6 and this
That's why you're experiencing this, because the date, which is Gai's one man's
The date was empty here, so we've put everything here.
Total, you're getting this from this method, okay? In our case, everything is fine.
You have a list, don't you? A list of an Excel file
You need to generate a certificate for your course and
The date there should show you a good, good date, like
that on June 20, 2026, we have already seen you and are now informing you as well.
You can comfortably format this, so we have the entire question
Remove the future date line for the student, just for Androl.
Mant Premium Boot Cam, we're showing you a good date, that's it.
I hope you like this video so much—it'll be especially popular, especially the part I fully explained.
Yeah, is it done this way? Say it, right
So, if you liked this video, please like it and share it with your friends.
If you haven't subscribed to the channel yet, please do so. See you soon.