ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 27th, 2005, 01:54 PM
charmed0rz charmed0rz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 142 charmed0rz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 49 m 31 sec
Reputation Power: 5
date help

can someone help me insert the date into mysql database i can't figure it out :S


what do i need to have the field set as? i want the date and time inserted.. do i set default as anything?


<cfif what is '1'>
<form action="test.cfm?what=2" method="post">
<input type="text" name="date" value="now()">
<input type="submit">

</cfif>



<cfif what is '2'>
test to see if its showing date
<cfoutput>#form.date#</cfoutput>
</cfif>

it just shows now()

Reply With Quote
  #2  
Old January 27th, 2005, 02:13 PM
wdn2000's Avatar
wdn2000 wdn2000 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Apr 2000
Posts: 1,058 wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 20 h 56 m 43 sec
Reputation Power: 16
Use now() in your insert.

It is MySQL, not HTML or CF.

Reply With Quote
  #3  
Old January 27th, 2005, 02:14 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,676 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 10 m 34 sec
Reputation Power: 53
Dude, I'm all for helping people, but come on now, did you even try to debug this? This is a no-brainer!

<input type="text" name="date" value="#now()#">

I'm worried that by helping people with "problems" like this that they're going to start to depend on the forum when they should be developing their debugging skills.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Last edited by kiteless : January 27th, 2005 at 02:17 PM.

Reply With Quote
  #4  
Old January 27th, 2005, 02:27 PM
charmed0rz charmed0rz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 142 charmed0rz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 49 m 31 sec
Reputation Power: 5
ok now it says #now()# instead of now()

Quote:
Originally Posted by kiteless
Dude, I'm all for helping people, but come on now, did you even try to debug this? This is a no-brainer!

<input type="text" name="date" value="#now()#">

I'm worried that by helping people with "problems" like this that they're going to start to depend on the forum when they should be developing their debugging skills.

Reply With Quote
  #5  
Old January 27th, 2005, 02:32 PM
charmed0rz charmed0rz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 142 charmed0rz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 h 49 m 31 sec
Reputation Power: 5
wdn2000 - thanks i thought it had to be defined in the form.. does it matter what the feild is set as? because when i insert it as text it works fine, but when i do it as datetime it shows: 0000-00-00 00:00:00

or maybe i can leave it as text, would i be able to sort it by date then if the field is text? :P


Quote:
Originally Posted by charmed0rz
ok now it says #now()# instead of now()

Reply With Quote
  #6  
Old January 27th, 2005, 02:48 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,676 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 10 m 34 sec
Reputation Power: 53
Ok Charmed, I'm really not trying to sound like a jerk, so let me back off a bit.

Let's look at the problem you are experiencing. First you said that when you output the variable on the form's action page, all that comes out is "now()". The first thing you should do is a <cfdump var="#form#"><cfabort> to see if that is the value that is coming into the page in the FORM scope.

The dump would tell you that "now()" is coming in from the form, so that should tell you that the problem must be in the form. If you go look at the form, the value of that input field is "now()". Hopefully you can see that this is what the problem is, that you are actually submitting the text string "now()" instead of using a ColdFusion variable?

So I told you to replace it with "#now()#". And you come back and tell me that when you output it on the page now you get the text string "#now()#".

So think about this for a second and you tell me what the problem is. I'll give you a hint: it is almost unbelievably easy.

Reply With Quote
  #7  
Old January 27th, 2005, 02:51 PM
wdn2000's Avatar
wdn2000 wdn2000 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Apr 2000
Posts: 1,058 wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 20 h 56 m 43 sec
Reputation Power: 16
This would be better answered in the MySQL forum. I'm at work in a Windows shop so I don't have my MySQL reference handy.

Personally, if I'm in a *NIX environment I use the integer timestamp and convert it to human-readable for display only.

-----

Just checked my CF ref and it shows now() as a CF date/time specifier... It could be there's something different about the way CF formats date/time and MySQL expects it. But, kiteless example of #now()# should work to display in the form. This introduces other possibilities for problems but that's probably better left for another day.

Last edited by wdn2000 : January 27th, 2005 at 02:54 PM.

Reply With Quote
  #8  
Old January 27th, 2005, 03:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,676 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 10 m 34 sec
Reputation Power: 53
wdn, I think you're digging in the wrong direction. He's not submitting the a date from his form, he's just submitting a string. All he needs to do is use the CF variable #now()# and wrap it in <cfoutput> like this:

<cfif what is '1'>
<cfoutput>
<form action="test.cfm?what=2" method="post">
<input type="text" name="date" value="#now()#">
<input type="submit">
<cfoutput>
</cfif>

Reply With Quote
  #9  
Old January 27th, 2005, 03:26 PM
wdn2000's Avatar
wdn2000 wdn2000 is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Apr 2000
Posts: 1,058 wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level)wdn2000 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 Days 20 h 56 m 43 sec
Reputation Power: 16
Quote:
Originally Posted by kiteless
wdn, I think you're digging in the wrong direction. He's not submitting the a date from his form, he's just submitting a string.


I was going by the first thing said:
can someone help me insert the date into mysql database

There is a now() in MYSQL so I was going that way. If all that needs to be done is the current time is inserted, the user doesn't have to see any of it....

Reply With Quote
  #10  
Old January 27th, 2005, 04:18 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,676 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 10 m 34 sec
Reputation Power: 53
Yep, I think charmed was also assuming it was some kind of date issue with MySQL and missing the fact that he wasn't passing a date at all.

And charmed, once you have the date using now() you may also need to use createODBCDate() on that value to get it into an ODBC format that the database will accept. Some databases will take the format that now() creates, others want a special ODBC format for the date. Give the value from #now()# a try and if that doesn't work try the ODBC formatting function.

Reply With Quote
  #11  
Old January 27th, 2005, 08:12 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,676 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 10 m 34 sec
Reputation Power: 53
Or of course you could do as wdn is suggesting, and drop the date completely from the form. Just use MySQL's now() function and use it in the query.

The real root of the issue isn't whether you pass the date from the form or use the SQL now() function inside the insert statement. The issue is the train of thought that we must go through when we encounter a problem and need to trace it back to the cause.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > date help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |