Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Getting Started / November 2007



Tip: Looking for answers? Try searching our database.

Date query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cybertek23 - 28 Nov 2007 16:53 GMT
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
CFMXPrGrmR - 28 Nov 2007 17:10 GMT
You can use the TimeFormat function on your date field.

http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt2105.htm#1113706
cybertek23 - 28 Nov 2007 17:14 GMT
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
Ian Skinner - 28 Nov 2007 17:19 GMT
> 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.
cybertek23 - 28 Nov 2007 17:39 GMT
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

<cfset yourDate1 = now()>

<cfoutput>
<cfset today =  #TimeFormat(yourdate1, 'dd/mm/yy')#>
<cfset yourDate2 = #TimeFormat(yourdate1, "HH:mm:ss")#>

#today# #yourdate2#
</cfoutput>
Ian Skinner - 28 Nov 2007 17:44 GMT
<cfoutput>
 <cfset today =  #dateFormat(yourdate1, 'dd/mm/yy')#>
 <cfset yourDate2 = #timeFormat(yourdate1, "HH:mm:ss")#>

 #today# #yourdate2#
 </cfoutput>

Two functions, dateFormat() and timeFormat(), you used the same function
twice.
Dan Bracuk - 28 Nov 2007 17:48 GMT
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.
cybertek23 - 29 Nov 2007 09:33 GMT
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.

[b]Number of query values and destination fields are not the same.[/b] I know
this is the date as it works with out this in there

<cfset yourDate1 = now()>

<cfoutput>
<cfset today = dateFormat(yourdate1, 'dd/mm/yy') />

<cfset yourDate2 = #TimeFormat(yourdate1, "HH:mm:ss")#>

<cfset today1=#today# &  " " & #yourdate2#>

</cfoutput>
Dan Bracuk - 29 Nov 2007 13:05 GMT
[q][i]Originally posted by: [b][b]cybertek23[/b][/b][/i]
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.

[/q]
Your interpretation is correct.  Your db is treating your function results as
text.  The reason is, it is text.
Ian Skinner - 29 Nov 2007 15:10 GMT
For inputing dates, you probably want to be using one of the
createODBCDate(), createODBCTime() or createODBCDateTime() functions.

The formatDate() and formatTime() functions are for the opposite, they
are for the display of date-time values.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.