使用日期和时间生成主键

i try to generate a primary key using date and time with php code.

but when i save the id change to 2147483647.

my code to get date and time is.

$dt = new DateTime("now", new DateTimeZone('Asia/Jakarta'));

then i print it to input form with readonly

<input type="text" class="form-control" id="idpost" name="idpost" value="<?php echo $dt->format('dmHis'); ?>" form="add_post" readonly>

Your id column is probably of type INT and SIGNED (default). This has a maximum value of 2147483647. With that date format, you're getting larger numbers (e.g. 3112133015).

If you want to use numbers that large either use a BIGINT column, which has a maximum value of 9223372036854775807 or use an UNSIGNED INT so that the maximum value becomes 4294967295.

its seems like its giving you timestamp convert that to a readable date/time php time

echo date('Y-m-d H:i:s', 2147483647);