To subtract hours from a date in swift we need to create a date first. Once that date is created we have to subtract hours from that, though swift does not provide a way to subtract date or time, but it provides us a way to add date or date component in negative value. In this example we’ll see how we can achieve the same.Let’s create a date first, let it be today, let today = Date()Now to modify this date we’ll use the add function with negative value, let modifiedDate = Calendar.current.date(byAdding: .hour, value: -2, to: today)!Now to see ... Read More
Recycler view is a more advanced version of listview and works based on View holder design pattern. Using recyclerview we can show grids as well as a list of items.This example demonstrates how to integrate RecyclerView by creating a beautiful student records app that displays student name with age.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Open build.gradle and add Recycler view library dependency.apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.example.andy.tutorialspoint" ... Read More
To check for Long overflow, we need to check the Long.MAX_VALUE with the subtracted long result. Here, Long.MAX_VALUE is the maximum value of Long type in Java.Let us see an example wherein long integers are subtracted and if the result is still more than the Long.MAX_VALUE, then an exception is thrown −The following is an example showing how to check for Long overflow −Example Live Demopublic class Demo { public static void main(String[] args) { long val1 = 70123; long val2 = 10567; ... Read More
To calculate age in MySQL from Date of Birth, you can use the following syntax −SELECT YEAR(CURRENT_TIMESTAMP) - YEAR(yourColumnName) - (RIGHT(CURRENT_TIMESTAMP, 5) < RIGHT(yourColumnName, 5)) as anyVariableName from yourTableName;To understand the above concept, let us create a table. The following is the query to create a table.mysql> create table AgeCalculatesDemo −> ( −> YourDateOfBirth datetime −> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the table with the help of insert command. These records are the DOBs through which we will calculate the age. The following is the ... Read More
Before getting into set random background color for recycler view example, we should know what is Recycler view in android. Recycler view is a more advanced version of the list view and it works based on View holder design pattern. Using recycler view we can show grids and list of items.This example demonstrates How to set the random background for Recyclerview by creating a beautiful student records app that displays student name with age.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 ... Read More
To get the last index, use the SUBSTRING_INDEX() function from MySQL. The syntax is as follows −SELECT yourColumnName1, ...N, SUBSTRING_INDEX(yourColumnName, ’yourDelimiter’, -1)as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table LastIndexString -> ( -> Id int, -> yourURL text -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using INSERT command. The query is as follows −mysql> insert into LastIndexString values(1, 'https −//www.example.com/home.html'); Query OK, 1 row affected (0.26 sec) mysql> insert into LastIndexString values(2, ... Read More
The post of Prime Minister of India, for one of the largest and most populated countries in the world, is not an easy position to hold. Since the Prime Minister of the country has to undergo a lot of pressure and work, there are obviously some perks that he or she will be eligible for.Let us see what is the salary of the prime minister is and what are the perks and luxuries that he can access when he is in the post of the prime minister.The monthly salary of the Prime Minister of India is approximately 1, 60, 000 ... Read More
To return a value from stored procedure, you need to use user defined session specific variable. Add @ symbol before variable name.For example, use @symbol for variable valido. The syntax for the same is as follows:SELECT @valido;Whenever you use select statement, you need to use @anyVariableName. The syntax is as follows:SELECT @anyVariableName;Here is the demo of stored procedure of return value. The query to create a stored procedure is as follows:mysql> create procedure ReturnValueFrom_StoredProcedure -> ( -> In num1 int, -> In num2 int, -> out valido int ... Read More
To get the creation date of a MySQL table, use create_time from information_schema.tables. The syntax is as follows −SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'yourDatabaseName' AND table_name = 'yourTableName';My table name is 'skiplasttenrecords' and database is ‘test’.Implement the above syntax for your database and table name. The query is as follows −mysql> SELECT create_time FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'test' −> AND table_name = 'skiplasttenrecords';The following is the output displaying the creation date −+---------------------+ | CREATE_TIME | +---------------------+ | 2018-11-29 15:47:14 | +---------------------+ 1 row in set (0.00 sec)
You can use backward slash followed by G i.e. \G instead of semicolon(;). The syntax is as follows to show records vertically in MySQL command line.SELECT *FROM yourTableName\GTo understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table showRecordsVertically -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (2.10 sec)Insert some records in the table using insert command. The query is as followsmysql> insert into showRecordsVertically ... Read More