Krantik Chavan has Published 278 Articles

How to select particular range of values in a MySQL table?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

826 Views

In order to select particular range of values in a MySQL table, you can use WHERE clause. Let us first create a table:mysql> create table DemoTable (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(200),    CustomerAge int,    isRegularCustomer bool ); Query OK, 0 rows affected ... Read More

Can I get Age using BirthDate column in a MySQL query?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

234 Views

To get Age using BirthDate column in a MySQL query, you can use datediff(). Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    DateOfBirth date ); Query OK, 0 rows affected (1.46 sec)Following is the query to insert some records ... Read More

MongoDB Regex Search on Integer Value?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

2K+ Views

To perform Regex search on integer value, you need to use $where operator. The syntax is as follows:db.yourCollectionName.find({ $where: "/^yourIntegerPatternValue.*/.test(this.yourFieldName)" });To understand the above concept, let us create a collection with document. The query to create a collection with document is as follows:> db.regExpOnIntegerDemo.insertOne({"StudentId":2341234}); {    "acknowledged" : true,   ... Read More

Get the names beginning with a particular character using LIKE in MySQL

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

723 Views

To get the names beginning with a particular character, you need to use LIKE. Let us first create a table:mysql> create table DemoTable (    StudentFirstName varchar(20) ); Query OK, 0 rows affected (1.01 sec)Following is the query to insert some records in the table using insert command:mysql> insert into ... Read More

How to convert string to 24-hour datetime format in MySQL?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

1K+ Views

To convert string to 24 hour datetime format in MySQL, you can use STR_TO_DATE() method. With that use the following format for datetime as the parameter:'%Y-%m-%d %H:%i:%s'Following is the syntaxSELECT STR_TO_DATE(yourColumnName, '%Y-%m-%d %H:%i:%s') FROM yourTableName;Let us first create a table:mysql> create table DemoTable (ArrivalDate varchar(200)); Query OK, 0 rows affected ... Read More

How to auto-increment value of tables to lower value in MySQL?

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

851 Views

If you’re using InnoDB engine, then you cannot set auto_increment value of tables to lower value. You need to change your engine from InnoDB to MyISAM.Note: The engine MyISAM allows you to set lower value. Here, we are using the same.According to the official documents:You cannot reset the counter to ... Read More

Period toTotalMonths() method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

77 Views

The total number of months for a particular Period can be obtained using the toTotalMonths() method in the Period class in Java. This method requires no parameters and it returns the total number of months in the Period in the form of a long value.A program that demonstrates this is ... Read More

Period of() method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

108 Views

The Period can be obtained with the given number of days, months and years using the of() method in the Period class in Java. This method requires a 3 parameters i.e. the number of days, the number of months and the number of years. Also, it returns the Period object ... Read More

Period parse() method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

537 Views

The Period instance can be obtained from a string value using the parse() method in the Period class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the Period instance obtained from the string value ... Read More

Period from() method in Java

Krantik Chavan

Krantik Chavan

Updated on 30-Jul-2019 22:30:25

114 Views

An instance of a Period object can be obtained from a Temporal object using the from() method in the Period class in Java. This method requires a single parameter i.e. the TemporalAmount and it returns the Period object that is obtained.A program that demonstrates this is given as followsExample Live Demoimport ... Read More

Advertisements