This function is used to get the timestamp value from the specified character string. SELECT TIMESTAMP_FORMAT(“”, “%Y”) as “Year of the date” This function helps to retrieve any particular value of the timestamp in any format that we wish. SELECT QUARTER (‘5’, ‘5’) AS “Date interval in quarters” This date function retrieves the quarter in which the specified date is present. SELECT MONTHS_BETWEEN ( ‘5’, ‘5’) AS “Month difference” This function helps to retrieve the number of months that are estimated between the two expressions specified in the arguments. SELECT NOW() as “current timestamp value” This function returns the timestamp value that depends on the execution of that timestamp function and the SQL statement which is executed by the currently specified parameter. SELECT MINUTE(‘2 08:36’) AS “current minutes” This function retrieves the minute value from the specified date value. SELECT HOUR( ‘2 08:36’) AS “current hour” It helps in retrieving only the hour part from the specified value. SELECT DAYS(‘2 08:36’) AS “current days” This function helps to get the integer value of the specified date format. SELECT DAYOFWEEK(“ 09:34:21”) as “Day of week in integer” It helps to retrieve the day of the year passed in the specified arguments which returns an integer value ranging between 1 to 7 where 1 stands for Monday while 7 for Sunday. SELECT DAYOFYEAR (“”) as “Day of the date” It helps to retrieve the day of the year as specified in the arguments. SELECT DAYOFWEEK (“”) as “Week of the date” This function helps to retrieve the day value between 1 to 7 where 1 stands for the first day of the week, 2 for Tuesday, and so on. SELECT DAYOFYEAR( ‘2 08:36’) AS “day of year” This function is used to retrieve the day value of the year which is specified. SELECT DAYNAME(“ 02:30:22”) as “Day of the date” The day portion can also be specified by using the CURRENT LOCALE LC_TIME which is a special register. The day portion from the specified expression is based on the locale name. This function helps us to retrieve the name of the day for the specified timestamp in form of the character string. This function helps us to retrieve the integer value ranging between 1 to 31 which stands for the day of the month from the specified datetime value. SELECT DATE_PART (yy,’2017‑01‑28′) AS DatePartValue This function helps us to retrieve a particular portion of the data from the passed date time value argument. Months and the total number of days between the two timestamps. This function is used to retrieve the age calculated between the current timestamp value and the specified argument and is returned in terms of years. SELECT DAY(‘5’) AS ” Day value of month” This function is used to retrieve the day value from the specified date-time value. SELECT ADD_ SECONDS (“”, 50000) as “ADD_SECONDS output” This function is used to add certain number of seconds in the specified expression and returns the value that is in datetime format having newly added seconds as specified in arguments. SELECT ADD_YEARS (“”, 5) as “ADD_YEARS output” This function is used to add certain number of years in the specified expression and returns the value that is in datetime format having newly added years as specified in arguments. SELECT ADD_HOURS (“”, 55) as “ADD_HOURS output” This function is used to add certain number of hours in the specified expression and returns the value that is in datetime format having newly added hours as specified in arguments. SELECT ADD_ MINUTES (“”, 1500) as “ADD_MINUTES output” This function is used to add certain number of minutes in the specified expression and returns the value that is in datetime format having newly added minutes as specified in arguments. SELECT ADD_DAYS(“”, 50) as “ADD_DAYS output” This function is used to add a certain number of days in the specified expression and returns the value that is in datetime format having newly added days as specified in arguments. SELECT DATE_ MONTHS (“”, 10) as “ADD_MONTHS output” This function is used to add the certain number of months in the expression and returns the value that is in datetime format having newly added months as specified in arguments. The purpose and description for each of the functions are also specified in the following table showing date functions of DB2. Let us now have a look at some of the additional date-related functions that are available in DB2. The output of the execution of the above query statement gives out the following resultant value of the current timestamp value as shown in the below image – SELECT current timestamp as "Current timestamp value" FROM sysibm.sysdummy1 We can make use of the following query statement to get the current timestamp value in DB2 – The output of the execution of the above query statement gives out the following resultant value of current time value as shown in the below image –
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |