Solved

Include Current Date in SQL Statement

Posted on 2009-05-13
6
469 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 46
Sql server, import complete table, using vb.net 9 43
"Emulate" TAB key when press Enter Key 3 44
Vb.net threads keep increasing 2 35
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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