Convert MySQL Timestamp to Unix Timestamp

AmitDiwan
Updated on 27-Sep-2019 07:58:58

1K+ Views

To convert MySQL timestamp to UNIX Timestamp, use the UNIX_TIMESTAMP(). Following is the syntax −select unix_timestamp(yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable(    Duetimestamp timestamp ); Query OK, 0 rows affected (2.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(now()); Query OK, 1 row affected (1.53 sec) mysql> insert into DemoTable values('2016-01-21 12:34:00'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable values('2018-05-01 02:00:00'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('2017-03-02 01:10:20'); Query OK, 1 row affected (10.19 sec)Display all records from ... Read More

Check If a Large Number Is Divisible by 25 in C++

Arnab Chakraborty
Updated on 27-Sep-2019 07:58:01

210 Views

Here we will see how to check a number is divisible by 25 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 25, when the last two digits are 00, or they are divisible by 25.Example Live Demo#include using namespace std; bool isDiv25(string num){    int n = num.length();    int last_two_digit_val = (num[n-2] - '0') * 10 + ((num[n-1] - '0'));    if(last_two_digit_val % 25 == 0)       return true;       return false; } int main() {    string num = "451851549333150";    if(isDiv25(num)){       cout

Replace AND with Ampersand in MySQL Database

AmitDiwan
Updated on 27-Sep-2019 07:57:41

752 Views

To replace & with an ampersand, use MySQL REPLACE(). Let us first create a table −mysql> create table DemoTable(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value varchar(100) ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('@amp'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable(Value) values('&'); Query OK, 1 row affected (1.09 sec) mysql> insert into DemoTable(Value) values('#amp'); Query OK, 1 row affected (0.28 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----+-------+ ... Read More

Find Average Based on Duplicate Varchar Values in MySQL

AmitDiwan
Updated on 27-Sep-2019 07:56:21

92 Views

Let us first create a table −mysql> create table DemoTable(    Value int,    Value2 varchar(100) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, '999.999.999.999'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(20, '888.888.888.888'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(30, '999.999.999.999'); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------+-----------------+ | Value | Value2 ... Read More

Find Whether a Number is the Power of Two in Python

Pavitra
Updated on 27-Sep-2019 07:56:11

252 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a number n, we need to check whether the given number is a power of two.ApproachContinue dividing the input number by two, i.e, = n/2 iteratively.We will check In each iteration, if n%2 becomes non-zero and n is not 1 then n is not a power of 2.If n becomes 1 then it is a power of 2.Let’s see the implementation below −Exampledef isPowerOfTwo(n):    if (n == 0):       return False    while (n != 1):       ... Read More

Check if a Large Number is Divisible by 20 in C++

Arnab Chakraborty
Updated on 27-Sep-2019 07:55:42

213 Views

Here we will see how to check a number is divisible by 20 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 20, when that is divisible by 10, and after dividing 10, the remaining number is divisible by 2. So the case is simple. If the last digit is 0, then it is divisible by 10, and when it is divisible by 10, then the second last element is divisible by 2, the number is divisible by 20.Example Live Demo#include using namespace std; bool isDiv20(string ... Read More

MySQL Update: Change Nothing in a Table

AmitDiwan
Updated on 27-Sep-2019 07:55:11

353 Views

Yes, we can do that. Let us first create a table −mysql> create table DemoTable(    Id int ); Query OK, 0 rows affected (1.02 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(201); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values(202); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(290); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(301); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------+ ... Read More

What Does SELECT IDENTITY Do in MySQL

AmitDiwan
Updated on 27-Sep-2019 07:53:46

2K+ Views

The @@identity returns the last inserted value in the auto_increment column in the current session. Let us first create a table −mysql> create table DemoTable(    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserName varchar(100) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserName) values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(UserName) values('Mike'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(UserName) values('Carol'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(UserName) values('Robert'); Query OK, 1 row affected (0.24 sec) ... Read More

Check Divisibility of a Large Number by 2, 3, and 5 in C++

Arnab Chakraborty
Updated on 27-Sep-2019 07:53:14

262 Views

Here we will see how to check a number is divisible by 2, 3 and 5 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 2, 3 and 5 if that number is divisible by LCM of 2, 3 and 5. So the LCM of 2, 3, 5 is 30. We have to check the number is divisible by 30 or not. A number is divisible by 30 when it is divisible by 10 (last digit is 0) and divisible by 3 (sum of all digits ... Read More

Fetch Maximum Corresponding Value from Duplicate Column Values in MySQL

AmitDiwan
Updated on 27-Sep-2019 07:52:33

195 Views

Let us first create a table −mysql> create table DemoTable(    ProductName varchar(100),    ProductPrice int ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Product-1', 56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Product-2', 78); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Product-1', 88); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Product-2', 86); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Product-1', 45); Query OK, 1 row affected (0.18 sec) mysql> insert into ... Read More

Advertisements