Last dumb question I promise! (referring to SQL da

Results 1 to 2 of 2

Thread: Last dumb question I promise! (referring to SQL da

  1. #1
    Tom Levesque Guest

    Default Last dumb question I promise! (referring to SQL da

    Yesterday Bill told me that VBScript Date()s and Now()s are actually the number of SECONDS and are only displayed as complex string values that people are used to. I found this very useful because I could now sort things by date, see if one date is older than another, etc. etc. HOWEVER what I did not realize was that was an VBSCRIPT date ... not an SQL date :) So,, my question now is if I do something like this:<BR><BR>SQL = "Create Table topics ( id integer primary key, title varchar not null, date_posted Date );"<BR><BR>conn.execute(SQL) <BR><BR>&#039 Btw - is "Date" the correct indentifier for the last column?<BR><BR>and then do this:<BR><BR>SQL = "INSERT INTO TABLE topics (...) VAULES(..., " & Now & ");"<BR><BR>conn.Execute(SQL)<BR><BR>SQL = "SELECT * FROM topics ORDER BY date_posted DESC;"<BR><BR>Set somevariable = conn.Execute(SQL)<BR><BR>Does this WORK? Considering the value stored in date_posted is a VBSCRIPT date and its really SQL that is trying to ORDER BY or SORT my recordset?

  2. #2
    Join Date
    Dec 1969

    Default No dumb questions! (But it's Friday)

    Data type may need to be DateTime, if Date doesn&#039t work.<BR><BR>To do the insert:<BR><BR>SQL = "INSERT INTO TABLE topics (...) VAULES(..., #" & Now & "#);"<BR><BR>What happens: Since you are doing string concatenation (the & operator), VBScript automatically converts the value of Now to a string. But Access (and, I presume, the Jet engine) need #...# around a date string. Note that every other DB that I know of needs &#039...&#039 around a date, just as around any string.<BR><BR>Finally...<BR><BR>Access (and, again, I presume the Jet engine) has Date() and Now() functions built in. So you *could* do that thus:<BR><BR>SQL = "INSERT INTO TABLE topics (...) VAULES(..., Now() );"<BR><BR>Notice that Now() is *inside* the quotes!<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts