Solved

Include Current Date in SQL Statement

Posted on 2009-05-13
6
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

628 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