简体   繁体   中英

How to save Excel date time cell into MySQL using VBA?

The mysql table has a DATETIME field. I want to INSERT a new row into this field using the cell data from the Excel worksheet. But I cannot use the datetime formatted cell value in a INSERT INTO query. How can I implement this?

Clarifying how you are using VBA would be helpful, but assuming that you are using VBA primarily to bring the data up to MySQL, you can handle a lot of your formatting right in your Excel workbook. For DATE type data,

=TEXT([the data],"YYYYMMDD")

is effective.

For DATETIME type data,

=TEXT([the data],"YYYYMMDDHHMMSS")

gets interpreted correctly at import by MySQL.

Hope that helps!

您可以创建一种以正确的方式表示日期时间的自定义格式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM