如何将Excel的日期格式转换为Sql日期格式?
问题描述:
我有学生出勤率Excel我在上个月的最后一天填写学生的出勤细节我在数据库中上传了excel表。当上传excel表时我收到此错误
I have Student Attendance Excel in Which I filling attendance detail of student at last of month I upload that excel sheet in database.When uploading excel sheet I getting this error
Error Uploading all Records.Object reference not set to an instance of an object
答
函数SQLDate(d)
SQLDate = WorksheetFunction。文字(d,yyyy-mm-dd hh:MM:ss)
结束功能
或者
如果登台表是一个选项,你可以使用
TEXT将日期转换为字符串(d,dd mmmm yyyy HH:MM:SS)。一旦数据在临时表中,您可以编写适当的SQL语句以插入到正确的表中。
Function SQLDate(d)
SQLDate = WorksheetFunction.Text(d, "yyyy-mm-dd hh:MM:ss")
End Function
or else
if staging table is an option, you could convert Excel date to string using
TEXT(d,"dd mmmm yyyy hh:mm:ss"). once the data is in staging table, you may write appropriate SQL statement to insert into correct table.