Journl5
Journl5
NOW():
NOW () function in SQL will give the current system's date and time.
Query:
2. CURDATE()
CURDATE () function in SQL will give the current system's date.
Query:
3. CURTIME()
CURTIME () function in SQL will give the current system time.
Query:
4. DATE()
Using the DATE () function in SQL, you can specifically extract the date from
the DATETIME datatype column.
Write a query to display the date from the given date and time, i.e., 2021-10-
24 18:28:44.
Query:
5. EXTRACT()
Using the EXTRACT() function in SQL, we can extract a specific part of date
and time according to our requirements: day, month, year, day, hour,
minute, etc.
Write a query to display the year from the given date, i.e., 24 th October 2021.
Query:
Write a query to display the month from the given date, i.e., 24 th October
2021.
Query:
Write a query to display the day from the given date, i.e., 24 th October 2021.
Query:
Write a query to display the hour from the given time, i.e., 19:10:43.
Query:
Write a query to display the minute from the given time, i.e., 19:10:43.
Query:
Write a query to display the seconds from the given time, i.e., 19:10:43.
Query:
6. DATE_ADD()
Using the DATE_ADD () function in SQL, we can add a specific time interval to
the given date.
Query:
Query:
Query:
7. DATE_SUB()
Using the DATE_SUB () function in SQL, we can remove a specific time
interval from the given date.
Write a query to remove an interval of 5 years from the given date, i.e.,
24th October, 2021.
Query:
Example 2:
Write a query to remove an interval of 5 months from the given date, i.e.,
24th October, 2021.
Query:
Example 3:
Write a query to remove an interval of 15 days from the given date, i.e.,
24th October, 2021.
Query:
8. DATEDIFF()
Using the DATEDIFF() function in SQL will give us the number of days that fall
between the two given dates.
Write a query to calculate the difference between two given dates, i.e.,
24th October, 2021, and 9th October, 2021.
Query:
CONCAT This function is used to concatenate two or more strings into a single string.
SELECT CONCAT('Hello', 'World');
Output: HelloWorld
Output: 11
REPLACE This function is used to replace a part of a string with another string.
SELECT REPLACE('Hello World', 'Hello', 'Hi');
Output: Hi World
TRIM This function is used to remove extra spaces from the beginning and end of a
string.
SELECT TRIM(' Hello World ');