Loading

MySQL Date Or Time Function Part-4

In MySQL Date Or Time Function Part-4 we will discuss about the DAYOFWEEK Function, DAYOFYEAR Function, EXTRACT Function, FROM_DAYS Function, FROM_UNIXTIME Function, HOUR Function, LAST_DAY Function.

DAYOFWEEK Function:- DAYOFWEEK Function is used for returning the weekday index from a given day.

Weekday index 1 for Sunday, 2 for Monday, 3 for Tuesday, 4 for Wednesday, 5 for Friday, 6 for Saturday, and 7 for Sunday

Syntax:- DAYOFWEEK(date)

Example:-

SELECT DAYOFWEEK(“2023-02-08”);

Output:- 4

DAYOFYEAR Function:- DAYOFYEAR Function is used for returning the day of the year from a given date.

Syntax:- DAYOFYEAR(date)

Example:-

SELECT DAYOFYEAR(“2023-02-08”);

Output:- 39

EXTRACT Function:- EXTRACT Function is used for extracting a portion of date or date-time value.

Syntax:- EXTRACT(part vale FROM date or date-time)

The part value may be any one of the following:-

MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, SECOND_MICROSECOND, MINUTE_MICROSECOND, MINUTE_SECOND, HOUR_MICROSECOND, HOUR_SECOND, HOUR_MINUTE, DAY_MICROSECOND, DAY_SECOND, DAY_MINUTE, DAY_HOUR, YEAR_MONTH

Example:-

SELECT EXTRACT(MINUTE FROM “2023-02-12 01:32:25”);

Output:- 32

SELECT EXTRACT(WEEK FROM “2023-02-12 01:32:25”);

Output:- 7

SELECT EXTRACT(MONTH FROM “2023-02-12 01:32:25”);

Output:-2

FROM_DAYS Function:- FROM_DAYS Function is used for returning date from a numeric date value. The date value will use within the Gregorian calendar.

Syntax:- FROM_DAYS(numeric date value)

Example:-

SELECT FROM_DAYS(738928);

Output:- 2023-02-12

FROM_UNIXTIME Function:- FROM_UNIXTIME Function is used for returning date or time into Unix timestamp. The format will be YYYY-MM-DD

Syntax:- FROM_UNIXTIME(unix_timestamp , format)

Example:-

SELECT FROM_UNIXTIME(999968445.09) ;

Output:- 2001-09-08 17:00:45.09

SELECT FROM_UNIXTIME(1676168445.09) ;

Output:- 2023-02-12 02:20:45.09

HOUR Function:- The HOUR Function is used for returning the hour part from a given date or date-time.

Syntax:- HOUR(date or date-time)

Example:-

SELECT HOUR(“2023-02-12 02:59:30”);

Output:- 2

LAST_DAY Function:- LAST_DAY Function is used for returning the last date of the month from a given date.

Syntax:- LAST_DAY(date)

Example:-

SELECT LAST_DAY(“2023-02-12”);

Output:- 2023-02-28

Read Also:-

MySQL Date Or Time Function Part-1
MySQL Date Or Time Function Part-2
MySQL Date Or Time Function Part-3
MySQL Date Or Time Function Part-5
MySQL Date Or Time Function Part-6
MySQL Date Or Time Function Part-7
MySQL Date Or Time Function Part-8

Read more detail about MySQL Date Or Time Function manual

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w
Verified by ExactMetrics