Skip to main content
August 3, 2007
Question

Now()

  • August 3, 2007
  • 3 replies
  • 463 views
I have field purchase_date in my table.
<cfquery datasource=#Request.datasource#>
insert into(purchase_date)
Values(<cfoutput>#Dateformat(Now(), "mm/dd/yyyy")#</cfoutput>)
</cfquery>
I expect today's date inserted in my table instade it saws 12/30/1890.
I kept tring never get todays date.
If there if microsoft access 2003 issue? How can I solve it.
Note: Rest of text fields are inserted as expected.
This topic has been closed for replies.

3 replies

Inspiring
August 4, 2007
> Values(<cfoutput>#Dateformat(Now(), "mm/dd/yyyy")#</cfoutput>)

You forgot the single quotes around the value. I would guess Access is treating the value as numeric date. But as mentioned do not use DateFormat(). Its better to use one of the other date functions that will insert a properly formatted "date" object.

A few minor comments about the code

1. The datasource value should be enclosed in double quotes
<cfquery datasource= "#Request.datasource# ">

2. You don't need to use CFOUTPUT here
Values(<cfoutput>#Dateformat(Now(), "mm/dd/yyyy")#</cfoutput>)

3. I assume the lack of table name is a typo
Insert into yourTableNameHere (purchase_date)

Inspiring
August 3, 2007
Don't use Dateformat for this type of thing. It returns a string, not a date. Better alternatives are:

1. Your db's equivalent function (in Access, it's also called Now() I believe)
2. cfqueryparam
3. CreateOdbcDate
4. CreateDate.
5. Cold Fusions now() function without the dateformat function.
Participating Frequently
August 3, 2007
I don't use Access, but at a minimum I'd use

Values(#createODBCDate(now())#)

instead of

Values(<cfoutput>#Dateformat(Now(), "mm/dd/yyyy")#</cfoutput>)