Skip to main content
Inspiring
November 28, 2007
Question

Date query

  • November 28, 2007
  • 3 replies
  • 752 views
Hi,

I know this is a really easy thing but i can not get this working properly today. I need to put a date into a database. I need the date to display in in the following format 20/09/2007 13:16:34 (dd/mm/yy hh:mm:ss). I need the time to be the 24 hour clock. I jsut cant get this to work. Please help
This topic has been closed for replies.

3 replies

Inspiring
November 28, 2007
Hopefully your database field is a date datatype and not a character datatype. If it is not, do something about it, storing dates as text is a horrible idea.

To insert data, do not worry about format. All you need is a datetime object. The cold fusion createdatetime function might come in handy.

When format does matter is when you are displaying the data. There is at least one, and maybe two ways to do this. The first is with the dateformat and timeformat functions you already know about. The second would be with database functions, depending on the database.
Inspiring
November 29, 2007
It now creates the date and time. I have tried to put it together but i think it is treating it a text as it will not put it into the database. My database field is a date/time and it need it to be 20/09/2007 13:16:34.

I have attached my code. I have also tried to combine it like <cfset today1=#today# & #yourdate2#> but that gives me the same error.



Number of query values and destination fields are not the same. I know this is the date as it works with out this in there
Inspiring
November 29, 2007
quote:

Originally posted by: cybertek23
It now creates the date and time. I have tried to put it together but i think it is treating it a text as it will not put it into the database. My database field is a date/time and it need it to be 20/09/2007 13:16:34.

I have attached my code. I have also tried to combine it like <cfset today1=#today# & #yourdate2#> but that gives me the same error.



Your interpretation is correct. Your db is treating your function results as text. The reason is, it is text.
Inspiring
November 28, 2007
cybertek23 wrote:
> Hi,
>
> I know this is a really easy thing but i can not get this working properly
> today. I need to put a date into a database. I need the date to display in in
> the following format 20/09/2007 13:16:34 (dd/mm/yy hh:mm:ss). I need the time
> to be the 24 hour clock. I jsut cant get this to work. Please help
>
Use the dateFormat() function for the date part and the timeFormat()
function for the time portion. Note: for a 24 hour/military hour
display use 'HH'. This is one place in CF where case matters 'hh' is 12
hour and 'HH' is 24 hour display.

Inspiring
November 28, 2007
I have tried to do that i have attatched my code but keep gettting the following in my date

d'd'/37/'y'y 17:37:37

Also how do i put it together to display and be able to insert it into my database
November 28, 2007
You can use the TimeFormat function on your date field.

Lookie here
Inspiring
November 28, 2007
Have you got an example of how i can use this. I have tried so many ways today. Dont think my brain is quite with it today