Convert Varchar to Date in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

6K+ Views

You can use date_format() to convert varchar to date. The syntax is as follows −SELECT DATE_FORMAT(STR_TO_DATE(yourColumnName, 'yourFormatSpecifier'), 'yourDateFormatSpecifier') as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table VarcharToDate    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Created_Time varchar(100),    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into VarcharToDate(Created_Time) values('12/1/2016'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

Run SQL Script in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

24K+ Views

To run SQL script in MySQL, use the MySQL workbench. First, you need to open MySQL workbench.The snapshot is as follows −Now, File -> Open SQL Script to open the SQL script.Alternatively, use the following shortcut key −Ctrl+Shift+OAfter that an option would be visible for you to choose your .sql file from the disk. In my system, the file is located on the Desktop. I will select the same “tblstudent” SQL file as shown in the following screenshot −After browsing .sql files, you need to select the option “Reconnect to database” as shown in the following screenshot −Now, it will ... Read More

Display Hour in K format (0-11) in AM/PM Format

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

197 Views

The “K” format in Java Date is used to display hour in 0-11 in AM/PM format. Use SimpleDateFormat("K") to get the same format.// displaying hour in K format SimpleDateFormat simpleformat = new SimpleDateFormat("K"); String strHour = simpleformat.format(new Date()); System.out.println("Hour in K format = "+strHour);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;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 and time ... Read More

Maximum Value of SMALLINT(6) Unsigned in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

2K+ Views

The maximum value of SMALLINT(6) unsigned in MySQL is 65535. The number 6 does not affect the actual range. It can only be used to display width on the command line.The Minimum Value signed is-32768The Maximum Value unsigned is65535The Maximum value signed is32767Let us understand this with zerofill and create a table using the following query.mysql> create table smallIntDemo -> ( -> FirstNumber smallint(6) zerofill -> ); Query OK, 0 rows affected (1.95 sec)Now you can insert records in the table using insert command. Whenever you insert beyond the range 65535, it will not insert in the table, since this ... Read More

Reverse Boolean Field in MySQL with Single Query

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

1K+ Views

Yes, you can use if() function from MySQL to reverse a boolean field. The syntax is as follows −UPDATE yourTableName SET yourBooleanColumnName = IF(yourBooleanColumnName, 0, 1);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table ReverseBooleanField    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> isValid BOOLEAN    -> ,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into ReverseBooleanField(isValid) values(true); ... Read More

Using LIKE for Two WHERE Clauses in MySQL

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

178 Views

You don’t need to use two where clauses. Use two conditions using the LIKE operator and AND operator.To understand how to use LIKE for this, let us create a table. The query to create a table is as follows −mysql> create table WhereDemo    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into WhereDemo values(101, 'Maxwell'); Query OK, 1 row affected (0.14 sec) mysql> insert into WhereDemo values(110, 'David'); Query ... Read More

Format Minutes in MM Format in Java

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

252 Views

The “mm” format is to format minutes i.e. 01, 02, 03, 04, etc. Here, we will use the following −SimpleDateFormat("mm");Let us see an example −// displaying minutes in mm format SimpleDateFormat simpleformat = new SimpleDateFormat("mm"); String strMinute = simpleformat.format(new Date()); System.out.println("Minutes in mm format = "+strMinute);Above, we have used the SimpleDateFormat class, therefore the following package is imported −import java.text.SimpleDateFormat;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 and time ... Read More

Alter Multiple Columns in a Single Statement in MySQL

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

2K+ Views

Alter multiple columns in a single statement with the help of CHANGE command. The syntax is as follows −alter table yourTableName change yourOldColumnName1 yourNewColumnName1 dataType, yourOldColumnName2 yourNewColumnName2 dataType, . . . NTo understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table AlterMultipleColumns −> ( −> Id int, −> Name varchar(200) −> ); Query OK, 0 rows affected (0.93 sec)Now we have two columns with Id and Name. We will alter both the columns.Here, we will alter ... Read More

Sum Values of a Single Row in MySQL

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

1K+ Views

You can use below syntax to sum values of a single row −Case 1 − The following is the syntax if your column does not have NULL value −SELECT yourColumnName1+yourColumnName2+yourColumnName3+.......+N as anyVariableName FROM yourTableName;Case 2 − If your column has NULL value then use this syntax −SELECT IFNULL(yourColumnName1, 0)+ IFNULL(yourColumnName2, 0)+ IFNULL(yourColumnName3, 0)+.............+N AS anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SumValueOfSingleRow    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue int,    -> SecondValue int,    -> ThirdValue ... Read More

Universities in the US Offering Scholarships in Script Writing

Ridhi Arora
Updated on 30-Jul-2019 22:30:24

99 Views

Creative writing allows to express one’s thoughts, emotions, and feelings along with the information shared or in the form of the information shared. One may have the dream to pursue scriptwriting from the U.S. A, but if one thinks that due to lack of finances this dream may never turn into reality; one is bound to be ignorant of the leading universities providing scholarship there.List of Universities of the U.S.A. Providing Scholarship for Script WritingLake Forest College in Chicago, Illinois, distributes scholarships to deserving applicants. The award amounts range between $1, 000-$5, 000 per academic year and are decided on ... Read More

Advertisements