Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1615
  • Last Modified:

Date() and Now() for MSSQL

I am getting an error on my date and now functions when trying to insert into the MSSQL database:

      strSQLTST = ("Insert into Transactions "_
      &"(buyerID, "_
      &"sellerID, "_
      &"Type, "_
      &"[date], "_
      &"[dateTime], "_
      &"Location, "_
      &"status, "_
      &"amountW) "_
      &"VALUES "_
      
      &"("&      User&      ","_
      &""&      -1&            ","_
      &""&      3&            ","_
      &"date()," _
      &"Now()," _
      &"'"& Home &"'," _
      &"'Complete'," _
      &""&      Deduct&      ")")

What do I use for MSSQL?  This was originally for Access =)  Thanks!
0
JuniorBee
Asked:
JuniorBee
  • 2
1 Solution
 
WMIFCommented:
use the vb functions and put quotes around them.

strSQLTST = ("Insert into Transactions "_
     &"(buyerID, "_
     &"sellerID, "_
     &"Type, "_
     &"[date], "_
     &"[dateTime], "_
     &"Location, "_
     &"status, "_
     &"amountW) "_
     &"VALUES "_
     
     &"("&     User&     ","_
     &""&     -1&          ","_
     &""&     3&          ",'"_
     &date() & "','" _
     &Now() & "'," _
     &"'"& Home &"'," _
     &"'Complete'," _
     &""&     Deduct&     ")")
0
 
WMIFCommented:
otherwise if you want the date and time from the sql server, use "getdate()".
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Why are you using TWO date fields - it looks like Date and DateTime?  A single field can cover both.
0
 
JuniorBeeAuthor Commented:
I forgot why I was using 2.  :/
I know it was for a good reason.  (laughs)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now