Query Between Two Dates in MySQL

Anvi Jain
Updated on 30-Jul-2019 22:30:24

18K+ Views

You can query between dates with the help of BETWEEN statement. The syntax is as follows −select *from yourTableName where yourColumnName between ‘yourStartingDate’ and curdate().Use curdate() or now(), both these functions will work. To understand the above syntax, let us create a table −mysql> create table BetweenDateDemo −> ( −> StartDate datetime −> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table with the help of the following query −mysql> insert into BetweenDateDemo values(date_add(now(), interval -1 year)); Query OK, 1 row affected (0.11 sec) mysql> insert ... Read More

ElementTree XML API in Python

Chandu yadav
Updated on 30-Jul-2019 22:30:24

12K+ Views

The Extensible Markup Language (XML) is a markup language much like HTML. It is a portable and it is useful for handling small to medium amounts of data without using any SQL database.Python's standard library contains xml package. This package has ElementTree module. This is a simple and lightweight XML processor API.XML is a tree like hierarchical data format. The 'ElementTree' in this module treats the whole XML document as a tree. the 'Element' class represents a single node in this tree. Reading and writing operations on XML files are done on the ElementTree level. Interactions with a single XML ... Read More

Remove Trailing Zeros in Decimal Value in MySQL

George John
Updated on 30-Jul-2019 22:30:24

11K+ Views

You can remove trailing zeros using TRIM() function. The syntax is as follows.SELECT TRIM(yourColumnName)+0 FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table removeTrailingZeroInDecimal    -> (    -> Id int not null auto_increment,    -> Amount decimal(5, 2),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.01 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into removeTrailingZeroInDecimal(Amount) values(405.50); Query OK, 1 row affected (0.22 sec) mysql> insert into removeTrailingZeroInDecimal(Amount) values(23.05); Query OK, ... Read More

Reluctant Qualifier in Java Regular Expressions

Rishi Raj
Updated on 30-Jul-2019 22:30:24

186 Views

The reluctant qualifier starts with the shortest string size as possible. If a match is found by the engine, the process continues to find more matches otherwise the engine adds a character to the searched string section and tries again. This continues until a match is obtained or the string is used up.The regex "B+?" is used to find the match in the string "SkyIsBlue".A program that demonstrates this is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       String regex = "B+?";       String str ... Read More

Format Date in MM-DD-YYYY HH:MM:SS Format in Java

Samual Sam
Updated on 30-Jul-2019 22:30:24

8K+ Views

Let us format date in mm-dd-yyyy hh:mm:ss format −// displaying date in mm-dd-yyyy hh:mm:ss format Format f = new SimpleDateFormat("mm-dd-yyyy hh:mm:ss"); String str = f.format(new Date()); System.out.println("Current Date in MM-dd-yyyy hh:mm:ss format = "+str);Since we have used the Format and SimpleDateFormat class above, therefore import the following packages. With that, we have also used the Date −import java.text.Format; import java.text.SimpleDateFormat; import java.util.Date;The following is an example −Example Live Demoimport java.text.Format; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; public class Demo { public static void main(String[] args) throws Exception { // displaying current date ... Read More

Return the Nth Record from MySQL Query

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

1K+ Views

To get the nth record from MySQL query, you can use LIMIT. The syntax is as follows −select *from yourTableName order by yourColumnName limit n, 1;To understand the above syntax, let us create a table. The following is the query to create a table −mysql> create table NthRecordDemo −> ( −> Id int, −> Name varchar(200) −> ); Query OK, 0 rows affected (0.92 sec)Insert some records in the table using the following query −mysql> insert into NthRecordDemo values(100, 'John'); Query OK, 1 row affected (0.09 sec) ... Read More

Use find to Find a Subsequence in Java Regexp

Fendadis John
Updated on 30-Jul-2019 22:30:24

89 Views

The find() method finds the subsequence in an input sequence that matches the pattern required. This method is available in the Matcher class that is available in the java.util.regex packageA program that uses the find() method to find a subsequence in Java is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("cool");       Matcher m = p.matcher("Java is cool");       System.out.println("Subsequence: cool");       System.out.println("Sequence: Java is cool");       if (m.find())          System.out.println("Subsequence found"); ... Read More

Use the Quantifier in Java Regular Expressions

Arushi
Updated on 30-Jul-2019 22:30:24

211 Views

In general, the ? quantifier represents 0 or 1 occurrences of the specified pattern. For example - X? means 0 or 1 occurrences of X.The regex "t.+?m" is used to find the match in the string "tom and tim are best friends" using the ? quantifier.A program that demonstrates this is given as follows:Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo {    public static void main(String args[]) {       Pattern p = Pattern.compile("t.+?m");       Matcher m = p.matcher("tom and tim are best friends");       System.out.println("The input string is: tom and tim are best ... Read More

Empty String in Not Null Column in MySQL

Samual Sam
Updated on 30-Jul-2019 22:30:24

3K+ Views

In PHP, the empty string equals to a NULL value, but in MySQL, the case is the different i.e. empty string is not equal to NULL value. To understand the above syntax, let us create a column with NOT NULL constraint while you can insert an empty string.Let us create a table. The query to create a table is as follows −mysql> create table EmptyStringNotNullDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(10) not null,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.83 sec)Now you can insert some records ... Read More

Format Date with DateFormat Medium in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

3K+ Views

DateFormat.MEDIUM is a constant for medium style pattern.Firstly, we will create date object −Date dt = new Date(); DateFormat dateFormat;Let us format date for different locale with DateFormat.MEDIUM −// CHINESE dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.CHINESE); // CANADA dateFormat = DateFormat.getDateInstance(DateFormat. MEDIUM, Locale.CANADA);The following is an example −Example Live Demoimport java.text.DateFormat; import java.util.Date; import java.util.Locale; public class Demo { public static void main(String args[]) { Date dt = new Date(); DateFormat dateFormat; // Date Format MEDIUM constant ... Read More

Advertisements