简体   繁体   English

如何使用VBA将Excel日期时间单元格保存到MySQL中?

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

The mysql table has a DATETIME field. mysql表有一个DATETIME字段。 I want to INSERT a new row into this field using the cell data from the Excel worksheet. 我想使用Excel工作表中的单元格数据在该字段中插入新行。 But I cannot use the datetime formatted cell value in a INSERT INTO query. 但是我不能在INSERT INTO查询中使用日期时间格式的单元格值。 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. 阐明您使用VBA的方式将很有帮助,但是假设您主要使用VBA将数据传递到MySQL,则可以在Excel工作簿中直接处理很多格式。 For DATE type data, 对于DATE类型的数据,

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

is effective. 是有效的。

For DATETIME type data, 对于DATETIME类型的数据,

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

gets interpreted correctly at import by MySQL. 在MySQL导入时正确解释。

Hope that helps! 希望有帮助!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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