Solved

Include Current Date in SQL Statement

Posted on 2009-05-13
6
466 Views
Last Modified: 2012-08-13
I have two sql statements that pull similar fields from different tables.
One sql statement just declares empty values so that it will have the same number of columns as another sql statement.
In one of my sql statements I return a date from the MSAccess database.
In the other sql statement I need to return the current date.
How would I do this?
Thank you
Below is the sql statement that I need to include the current date... See Date() as DateCreated.
 

        str = "SELECT 0 AS TaskCarsDetailID, TaskDetailsLU.TaskDetailsID, 0 AS Completed, " _

        & " TaskDetailsLU.TaskDetails, '""' AS TaskCarNotes, Date() AS DateCreated" _

        & " FROM TaskDetailsLU where TaskID = " & miTaskID & ""

Open in new window

0
Comment
Question by:Sheritlw
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Assisted Solution

by:carlnorrbom
carlnorrbom earned 250 total points
ID: 24382265
Hi,
" & DateTime.Now.ToString() & "
should to the trick.
/Carl.
0
 

Author Comment

by:Sheritlw
ID: 24382271
I need just the date... What is it for that?
Thanks
0
 
LVL 8

Expert Comment

by:SNilsson
ID: 24382273
Use Getdate() to return it.
  str = "SELECT 0 AS TaskCarsDetailID, TaskDetailsLU.TaskDetailsID, 0 AS Completed, " _

        & " TaskDetailsLU.TaskDetails, '""' AS TaskCarNotes, Getdate() AS DateCreated" _

        & " FROM TaskDetailsLU where TaskID = " & miTaskID & ""

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 8

Assisted Solution

by:SNilsson
SNilsson earned 250 total points
ID: 24382305
Or you can use now() as below
 str = "SELECT 0 AS TaskCarsDetailID, TaskDetailsLU.TaskDetailsID, 0 AS Completed, " _

        & " TaskDetailsLU.TaskDetails, '""' AS TaskCarNotes, '" & Now() & "' AS DateCreated" _

        & " FROM TaskDetailsLU where TaskID = " & miTaskID & ""

Open in new window

0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 24382356
Hi,
" & DateTime.Now.ToShortDateString() & "
0
 

Accepted Solution

by:
Sheritlw earned 0 total points
ID: 24382357
Since I am using MS Access, I need to use the correct syntax.
The solution is
#" & Today.Date() & "# AS DateCreated

Thanks for your help.  I will split the points between you.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now