viernes, 23 de mayo de 2025

Date Practice

SELECT 
    NOW() AS Today,
    DATE_SUB(NOW(), INTERVAL 1 DAY) AS Yesterday,
    DATE_ADD(NOW(), INTERVAL 1 DAY) AS Tomorrow,
    ADDTIME(NOW(), '01:01:00') AS Today_1_Hour_1_Min,
    DATEDIFF(NOW(), DATE_SUB(NOW(), INTERVAL 13 DAY)) AS Days_Difference_Between_2_Dates;




mysql> select now() Today,date_sub(now(),interval 1 day) Yesterday, date_add(now(),interval 1 day) Tomorrow,addtime(now(),'1:1') today_1_hour_1_min,datediff(now(),date_sub(now(),interval 13 day)) days_difference_between_2_dates\G;
*************************** 1. row ***************************
                          Today: 2025-05-24 01:25:42
                      Yesterday: 2025-05-23 01:25:42
                       Tomorrow: 2025-05-25 01:25:42
             today_1_hour_1_min: 2025-05-24 02:26:42
days_difference_between_2_dates: 13


---------------

Date format

mysql> select date_format(now(),'%a-%d-%b-%Y') TODAY;
+-----------------+
| TODAY           |
+-----------------+
| Sat-24-May-2025 |
+-----------------+


select FROM_UNIXTIME(1447430881,'%a-%d-%b-%Y') TODAY;
+-----------------+
| TODAY           |
+-----------------+
| Fri-13-Nov-2015 |
+-----------------+
https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

martes, 6 de mayo de 2025

Date time type

 

Data TypeZero Value
DATE'0000-00-00'
TIME'00:00:00'
DATETIME'0000-00-00 00:00:00'
TIMESTAMP'0000-00-00 00:00:00'
YEAR0000


https://dev.mysql.com/doc/refman/8.0/en/date-and-time-types.html

Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

 

Integer Types (Exact Value) - INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT

MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINTMEDIUMINT, and BIGINT. The following table shows the required storage and range for each integer type.

Table 13.1 Required Storage and Range for Integer Types Supported by MySQL

TypeStorage (Bytes)Minimum Value SignedMinimum Value UnsignedMaximum Value SignedMaximum Value Unsigned
TINYINT1-1280127255
SMALLINT2-3276803276765535
MEDIUMINT3-83886080838860716777215
INT4-2147483648021474836474294967295
BIGINT8-2630263-1264-1