Solved

Include Current Date in SQL Statement

Posted on 2009-05-13
6
467 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 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

25 Experts available now in Live!

Get 1:1 Help Now