简体   繁体   English

如何从选定的Excel工作表单元格中添加时间戳

[英]How to add time stamp in macro from selected excel sheet cells

My vba code pulls data of last "11" hours from Database. 我的vba代码从数据库中提取最后“11”小时的数据。 I want to pull data of my own time like "between (1/4/19 1:30 & 13/4/19 1:30)".Also want to add the data in sheet 1 like a table. 我想把我自己时间的数据拉到“之间(1/4/19 1:30和13/4/19 1:30)”。还要像表格一样在表格1中添加数据。 May i know how to add this custom time & make it a table using macro code. 我可以知道如何添加这个自定义时间并使用宏代码使其成为一个表。

Option Explicit

Sub DbConnection()
' NA Query connection with DB
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strConn As String
Dim mssql As String

strConn = "Driver={Redshift (x86)};Server=abc;Database=xyz;UID=abc;PWD=12345; Port=1234"
cn.Open strConn
cn.CommandTimeout = 60
mssql = "(using this line in SQL query here)"

where review_completed_timestamp_utc::TIMESTAMP > current_timestamp - interval'11 hour'

rs.Open mssql, cn
Sheets(1).Range("A2").CopyFromRecordset rs
End Sub

For the SQL part, since you didn't provide the names, you can do somenthing like this: 对于SQL部分,由于您没有提供名称,您可以像这样进行somenthing:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

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

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