AmitDiwan has Published 10744 Articles

Get beginning and end date from a specific year in MySQL

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:11:02

559 Views

For this, use MySQL YEAR() function. Let us first create a table −mysql> create table DemoTable1843      (      StartDate date,      EndDate date      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1843 values('2019-01-21', ... Read More

Multiplying column with NULL row in MySQL?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 06:04:14

488 Views

To multiply with NULL row, you can use COALESCE(). Let us first create a table −mysql> create table DemoTable1842      (      NumberOfItems int,      Amount int      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert ... Read More

Return records that do not have a value in a certain field with two SELECT statement in a single MySQL query

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 05:59:15

153 Views

For this, you can use WHERE clause along with subquery. Let us first create a table −mysql> create table DemoTable1840      (      UserName varchar(20),      UserType ENUM('GUEST', 'ADMIN')      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command ... Read More

What is the fastest way to insert a large number of rows into a MySQL table?

AmitDiwan

AmitDiwan

Updated on 26-Dec-2019 05:57:54

229 Views

The syntax for the fastest way is given below. Here, we have used INSERT INTO just once and formed an optimized way −insert into yourTableName values(NULL, yourValue1', yourValue2), (NULL, yourValue1', yourValue2), ....N;Let us first create a table −mysql> create table DemoTable1839      (      ClientId int NOT NULL ... Read More

PHP to check substring in a string

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:27:56

253 Views

To check substring in a string, the code is as follows in PHP −Example Live DemoOutputThis will produce the following output−String = How I Met Your Mother Substring = Mother Substring found successfullyExampleLet us now see another example − Live DemoOutputThis will produce the following output−String = In the Heart of Sea ... Read More

How to add days to $Date in PHP?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:25:04

3K+ Views

To add days to $Date in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output−Displaying date... Date = 2019-11-11 Displaying updated date... 2019-12-01ExampleLet us now see another example − Live DemoOutputThis will produce the following output−Displaying Date...2019/11/11 Displaying Updated Date... 2019/12/06

How to convert string to boolean in PHP?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:22:19

761 Views

To convert string to boolean in PHP, the code is as follows. Use the filter_val() method−Example Live DemoOutputThis will produce the following output−Displaying Sunday as first day of a week... First day (next week) = Sunday - 15/12/2019 bool(false)ExampleLet us now see another example − Live DemoOutputThis will produce the following output−bool(false) ... Read More

How to get first day of week in PHP?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:20:17

2K+ Views

To get the first day of the week in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output −First day = Monday - 09/12/2019ExampleLet us now see another example − Live DemoOutputThis will produce the following output −Displaying Sunday as first day of a week... First day ... Read More

How to get the first element of an array in PHP?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:17:45

302 Views

To get the first element of an array in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−Array value ... Value 1 = 150ExampleLet us now see another example − Live DemoOutputThis will produce the following output −Value 1 = 150

How to get random value out of an array in PHP?

AmitDiwan

AmitDiwan

Updated on 24-Dec-2019 12:15:57

394 Views

To get random value out of an array in PHP, the code is as follows−Example Live DemoOutputThis will produce the following output −Array values ... Value 1 = 150 Value 2 = 100 Value 3 = 120 Value 4 = 110 Value 5 = 115 Value 6 = 103 Value 7 ... Read More

Advertisements