You can change the date format in PHP using date() fucntion. The syntax is as follows −date(d/m/Y, yourDateTimeVariable);In PHP, convert string to date using strtodate(). Here is the PHP code used to format the datetime −$LogintDate = strtotime('2019-01-12'); echo date('d/m/Y', $LogintDate);The snapshot of code is as follows −The following is the output −12/01/2019You can achieve in MySQL with the help of date_format() function. The syntax is as follows −SELECT DATE_FORMAT(yourColumnName, ’%d/%m/%Y’) as anyVariableName FROM yourTableName;To understand the above syntax, let us create a table −mysql> create table Date_FormatDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> ... Read More
Definition and UsageThe srand() function is used to seed the random number generaror. Seeding initializes the random number generator. Most random number generators need initial seeding. In PHP, use of srand() function is optional as it is done automatically.This function doen't have any return value.Syntaxsrand ([ int $seed ] ) : voidParametersSr.NoParameter & Description1seedan integer to be used as seed. If not given, a random number is givenReturn ValuesThis function doesn't return any value.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoThis example the random number generator is first initialized before employing ... Read More
To select a single row in MySQL, you can use LIMIT. At first, let us create a table. The query to create a table is as follows −mysql> create table selectWithPrimaryKey -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into selectWithPrimaryKey(Name, Age, Marks) values('Larry', 24, 98); Query OK, 1 row affected (0.15 sec) mysql> insert into ... Read More
Definition and UsageThe sqrt() function returns square root of a positive float number. Since square root for negative number is not defined, it returns NAN. This is one of the most commonly used functions.This function always returns a floating point number.Syntaxsqrt ( float $arg ) : floatParametersSr.NoParameter & Description1arga number whose square root is to be obtainedReturn ValuesPHP sqrt() function returns square root of the given arg number. For negative number, the function returns NAN.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculate square root of 100−OutputThis will produce following ... Read More
Definition and UsageThe sinh() function calculates hyperbolic sine of given angle in radians. A hyperbolic sine function is defined assinh(x) = (ex – e-x))/2This function returns a float value between Π and -Π.Syntaxsinh( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value that represents angle in radiansReturn ValuesPHP sinh() function returns hyperbolic sine ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates sinh(pi/2) and returns 2.3012989023073 which is also the result of formula (ex – e-x))/2−OutputThis will produce following result −sinh(M_PI_2) = 2.3012989023073 using formula = ... Read More
Convert dd/mm/yyyy string to Unix timestamp with the help of UNIX_TIMESTAMP(). The syntax is as follows −SELECT UNIX_TIMESTAMP(STR_TO_DATE(yourColumnName, '%d/%m/%Y')) 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 ConvertddmmyyyyInUnixTimeStamp -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Created_at varchar(30), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ConvertddmmyyyyInUnixTimeStamp(Created_at) values('10/11/2012'); Query OK, 1 row affected (0.21 sec) mysql> ... Read More
Get hash value of each row using MD5() function from MySQL. The syntax is as follows −SELECT MD5(CONCAT(yourColumnName1, yourColumnName2, yourColumnName3, .......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 getHashValueForEachRow -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> Age int, -> Marks int, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (1.25 sec)Insert records in the table using insert command. The query is as follows −mysql> insert into getHashValueForEachRow(Name, Age, ... Read More
Definition and UsageThe sin() function returns the sine ratio of given angle in radians. In trigonometry, sine of an angle is defined as ratio of lengths of opposite side and hypotenuse.sin(x) = opposite/hypotenuseIf x=90 degree, sin(x) = 1 as opposite side of right angle is a hypotenuseThis function returns a float value.Syntaxsin ( float $arg ) : floatParametersSr.NoParameter & Description1argA floating point value that represents angle in radiansReturn ValuesPHP sin() function returns sine ratio of given parameter.PHP VersionThis function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.Example Live DemoFollowing example calculates sin(pi/2) and returns 1. Sine ratio of 90 deg is ... Read More
You can use CASE statement in MySQL to map keys to values for an individual field in select query. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, yourColumnName3, .........N ( CASE WHEN yourColumnName = 1 THEN 'ENABLED' ELSE 'DISABLED' END ) AS anyVariableName FROM yourTableName;You can use IF() function also for the same purpose. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, yourColumnName3, .........N ,IF(yourColumnName, 'ENABLED', 'DISABLED') 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 MapKeys -> ( ... Read More
Definition and UsageThe round() function proves useful in rounding any floating point number upto a desired precision level. Positive precision parameter causes the number to be rounded after decimal point, whereas with negative precision, rounding occurs before decimal point. Precision is 0 by default.For example, round(10.6) returns 11, round(10.2) returns 10. The function always returns a floating point number.This function also has another optional parameter called mode takes one of the redefined constants described later.Syntaxround ( float $value , int $precision , int $mode ) : floatParametersSr.NoParameter & Description1valueA float number to be rounded2precisionnumber of decimal digits to round to. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP