Hey everybody. In this topic I have a super quick video on getting the current date and time in MySQL. Let's create a temporary table.
At the end of this topic we'll delete it. Create, table. I'll name this table test.
We will have three columns. The current date, I'll name the column my date. The data type is date.
My time, the data type is time, then we'll combine both. My date time, the data type is date time. Let's create this table. It was created successfully.
Then I will select all from our table test. We have three columns. A date, a time, and a date time, which combines both.
So how do we get the current date? Maybe we need to create a timestamp of when some event happened. Maybe a higher date for our employees. So I'm going to insert into the name of my table test some values. For the currentDate, there is a built-in function.
current underscore date, then add a set of parentheses. This function will return the currentDate. For the currentTime, there is a currentTime function. Add a set of parentheses to the end of that function.
For the date time, you could just say now, then add a set of parentheses. After inserting this row, let's select all from our table test. Here's the current date of me filming this video. October 21st, 2022. The time is 7 in the morning.
The current date time is October 21st, 2022, 7 in the morning. A date time would probably be good for some sort of... transaction you need to record. For the time being, I'm going to set the current time to be null, as well as the date time to be null.
Now, if you were to take your current date, then add plus one, this part of my statement would refer to tomorrow. October 22nd. If you were to take your current date, minus one, that would technically be yesterday, October 20th. You could do something similar with your time and date time.
You can add or subtract seconds, but I think that's pretty self-explanatory. We don't need this test table anymore, so we can delete it. Drop table test.
And it's gone. All right, everybody. So that was a super quick topic, but I thought I needed to cover it. That is how to get the current date, time, and date time in MySQL.