Found 4381 Articles for MySQL

How can we know about the starting range of TIMESTAMP data type with the help of MySQL FROM_UNIXTIME() function?

radhakrishna
Updated on 28-Jan-2020 10:43:55

153 Views

As we know that this function converts a number of seconds into TIMESTAMP value. So by providing 0 seconds as the argument, it will give us the starting range of TIMESTAMP data type.mysql> Select FROM_UNIXTIME(0); +-------------------------+ | FROM_UNIXTIME(0)        | +-------------------------+ | 1970-01-01 05:30:00     | +-------------------------+ 1 row in set (0.00 sec)Now if we will change the argument from 0 to 60 seconds then the time will be changed by 01 minutes.mysql> Select FROM_UNIXTIME(60); +-------------------------+ | FROM_UNIXTIME(60)       | +-------------------------+ | 1970-01-01 05:31:00     | +-------------------------+ 1 row in set (0.00 sec)

In MySQL, how can I convert a number of seconds into TIMESTAMP?

Sravani S
Updated on 28-Jan-2020 10:44:24

1K+ Views

It is exactly reverse of UNIX_TIMESTAMP() and can be done with the help of FROM_UNIXTIME() function. For example, 11576070 seconds would be TIMESTAMP ‘1970-05-15 05:04:30’.mysql> Select FROM_UNIXTIME(11576070); +--------------------------------+ | FROM_UNIXTIME(11576070)        | +--------------------------------+ |      1970-05-15 05:04:30       | +--------------------------------+ 1 row in set (0.00 sec)

Why I got output 0(Zero) on converting date like ‘1965-05-15’ to TIMESTAMP?

mkotla
Updated on 28-Jan-2020 10:50:53

353 Views

As we know that with the help of MySQL UNIX_TIMESTAMP function, we can produce the number of seconds from given date/DateTime. But when we try to convert a date like ‘1965-05-15’ it would give 0(Zero) as output because the range of TIMESTAMP is between ‘1970-01-01 00:00:01’ to ‘2038-01-19 08:44:07’. Hence, the date values beyond TIMESTAMP range cannot be converted and will return 0 as output always.Examples are given below −mysql> Select UNIX_TIMESTAMP ('1965-05-15'); +----------------------------------------------+ | unix_timestamp('1965-05-15 05:04:30')        | +----------------------------------------------+ |                                   ... Read More

Is it necessary to select the database each time we begin a MySQL session?How can it be done?

Ayyan
Updated on 28-Jan-2020 10:23:55

91 Views

The database is created only once but it is necessary to select it each time we begin a MySQLsession. It can be done with the help of USE db_name statement on MySQL command line tool.mysql> Use Query; Database changedIt shows that we are now using query database.We can also select the database while invoking the MySQL from Windows command line. It can be done with the help of the following command −C:\Program Files\MySQL\bin>mysql -u root -p query Enter password: *****Here, query is the name of the database we are going to use for current MySQL sessionRead More

Are MySQL database and table names case-sensitive?

Monica Mona
Updated on 30-Jul-2019 22:30:21

971 Views

Actually, the case sensitivity of database and table name depends a lot on the case sensitivity of the underlying operating system. Hence, we can say that such names are not case sensitive in Windows but are case sensitive in most varieties of Unix.

How can we display a list of currently existing MySQL databases on the server?

Chandu yadav
Updated on 28-Jan-2020 10:24:46

105 Views

The SHOW DATABASES command is used to display the list of currently existing MySQL databases.mysql> Show Databases; +-----------------------------+ | Database                    | +-----------------------------+ | information_schema          | | gaurav                      | | mysql                       | | performance_schema          | | query                       | | query1                      | | sys                         | | tutorials                   | +-----------------------------+ 8 rows in set (0.02 sec)

What kind of output is produced by UNIX_TIMESTAMP() function?

Giri Raju
Updated on 28-Jan-2020 10:25:19

145 Views

The function UNIX_TIMESTAMP produce the output in seconds i.e this function will convert the specified date or datetime value into a total number of seconds.For example, the date ‘1970-05-15 05:04:30’ would be converted to total 11576070 seconds by UNIX_TIMESTAMP function.mysql> select UNIX_TIMESTAMP('1970-05-15 05:04:30'); +---------------------------------------+ | UNIX_TIMESTAMP('1970-05-15 05:04:30') | +---------------------------------------+ | 11576070                              | +---------------------------------------+ 1 row in set (0.09 sec)

How can we create our own choice MySQL database?

Anjana
Updated on 28-Jan-2020 10:28:48

150 Views

CREATE DATABASE db_name can be used to create our own choice MySQL database. For example to create a database named Sample, we should have to run the command as follows −mysql> CREATE DATABASE Sample; Query OK, 1 row affected (0.04 sec)

How can I store ‘0000-00-00’ as a date in MySQL?

Anvi Jain
Updated on 28-Jan-2020 10:31:35

2K+ Views

For storing the date like ‘0000-00-00’ in a column of MySQL table, we must have to set the SQL mode to ‘allow_invalid_date’. Following example will demonstrate it −mysql> SET sql_mode = 'allow_invalid_dates'; Query OK, 0 rows affected, 1 warning (0.03 sec) mysql> Create table test_date(date_order date); Query OK, 0 rows affected (0.45 sec) mysql> Insert into test_date(date_order) values('0000-00-00'); Query OK, 1 row affected (0.04 sec) mysql> Select * from test_date; +------------+ | date_order | +------------+ | 0000-00-00 | +------------+ 1 row in set (0.00 sec)

What is the difference between YEAR(2) and YEAR(4) in MySQL?

Sreemaha
Updated on 19-Jun-2020 13:41:15

616 Views

YEAR(2) stores a year in 2-digit format. For example, we can write 69 to store 1969 a year. In YEAR (2), the year can be specified from 1970 to 2069 (70 to 69).YEAR(4) stores a year in 4-digit format. For example, we need to write 19669 to store 1969 as a year. In YEAR (4), the year can be specified from 1901 to 2155.MySQL interprets 2-digit year values with the assistance of following rules:Year values within the vary 00-69 are converted to 2000-2069.Year values in the range 70-99 are converted to 1970-1999.We must not store date values as a 2-digit ... Read More

Advertisements