我有一个使用Powershell更新数据的MySQL数据库。我可以更新到任何文本列,但我对数据类型为datetime的“time”列有问题。根据MySQL文档,日期时间格式为YYYY-MM-DD HH:MM:SS (https://dev.mysql.com/doc/refman/5.1/en/datetime.html)
以这种格式获取日期/时间的等效powershell命令是: get-date -format G (https://technet.microsoft.com/en-us/library/ee692801.aspx)
当我将该时间写入一个变量并尝试更新一条记录时,该记录仍然为空,并且我假定数据类型为off,因为我可以写入整数和文本列。
有谁知道如何确保正确的数据类型,以便我可以更新记录?
发布于 2015-04-22 00:28:07
试一试
get-date -Format "yyyy-MM-dd hh:mm:ss"发布于 2015-11-06 23:31:44
之前的答案是接近,但小时需要是"HH“而不是"hh”,否则您将以所有PM时间作为AM插入/查询结束
# Gets the current datetime in correct format for a MySQL query
[string]$mySqlDateTime = get-date -Format "yyyy-MM-dd HH:mm:ss"
# Assuming you have a [datetime] variable named $datetime,
# use the following to get the correct format for a MySQL query
[string]$mySqlDateTime = $datetime.ToString("yyyy-MM-dd HH:mm:ss")https://stackoverflow.com/questions/29777806
复制相似问题