Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add timestamp with interval starting from Current time with interval 1 minutes for every row in MYSQL?

In example, I have something like,

Number_index
1
2
3
4
etc

for example, using NOW() will give time stamp "10/24/2022 12:00:00"
I want to add timestamp which will be something like

Number_index Time_Stamp
1 10/24/2022 12:00:00
2 10/24/2022 12:01:00
3 10/24/2022 12:02:00
4 10/24/2022 12:03:00
etc etc

Would you please explain how to do that in mysql?
Thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can use the TIMESTAMPADD() function here:

SELECT Number_index,
       TIMESTAMPADD(MINUTE, Number_index - 1, NOW()) AS Time_Stamp
FROM yourTable
ORDER BY Number_index;

The above is one option if you want view your output as described. If instead you want to update your table, then use:

UPDATE yourTable
SET Time_Stamp = TIMESTAMPADD(MINUTE, Number_index - 1, NOW());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading