Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    Question DateTime using Flex and CF? Head scratcher! :p

    Hi all,

    I have a column in my MySQL database typed as DATETIME, and i am trying to pass the value from a datefield in Flex via ColdFusion to the db, but for some reason it's just not hapening, i keep getting errors, here's one of them:

    Code:
    faultCode:Server.Processing faultString:'Unable to invoke CFC - Error Executing Database Query.' faultDetail:'Data truncation: Incorrect datetime value: '30/06/2009' for column 'date' at row 1'
    So here's the code i'm using to send it to the db (from Flex):
    Code:
    private function insertHandler(event:MouseEvent):void
    {
        ro.Insert(dateField.text);
    }
    ('ro' is my remote object and 'Insert' is my method for the CFC)

    so here's my CFC code:
    Code:
    <cffunction name="Insert" access="remote" returntype="Any">
    	
    	<cfargument name="dateInput" type="Date" required="yes">
    	
    	<cfquery  name="qInsert" datasource="#data#">
    	INSERT INTO testing (date)
    	VALUES  ('#arguments.dateInput#')
    	</cfquery>
    	
    	
    	
    	</cffunction>
    I've tried all sorts of different syntax to get this to work, and i'm just out of ideas, do i have to cfset the argument to a data type dd/mm/yyyy (as i belive the MySQL column is in?) or do i have to send another value from the dateField in Flex? ie data instead of text? I have tried that but it didn't seem to work.

    Really hoping someone here can help me sort this out

    Many thanks in advance guys and gals!!!!!

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by loki421 View Post
    do i have to cfset the argument to a data type dd/mm/yyyy (as i belive the MySQL column is in?) or do i have to send another value from the dateField in Flex? ie data instead of text? I have tried that but it didn't seem to work.
    It looks like you've already come to this conclusion, but the problem seems to be with the database query function itself. I would suggest logging the generated query so you can run it manually if need be for testing, and inspect it for errors. The MySQL DATETIME format is 'YYYY-MM-DD HH:MM:SS', so you need to update that. If you just want to store the date you can change the column to a DATE field instead, though MySQL will store a date with a time of midnight if you just specify the date for DATETIME. Passing it in as a string will work fine; you don't need to convert it to "data".

  • #3
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Thanks, but i've got my MySQL column set to DATE and not DATETIME, this is why i'm getting confused here, it's displaying in the query browser as 2009-06-20 with no time, and yet when it comes through the app via CF it's showing time too??

    I've heard that you can format the date via the CF query (DateFormat etc) but i've done some Googling and not found anything that really makes sense.... Any ideas what's going on here? Is there a way to format MySQL directly?

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by loki421 View Post
    Is there a way to format MySQL directly?
    There is, in fact, a DATE_FORMAT() function for MySQL. MySQL won't be adding the time to your column if it is DATE to begin with though; something in your app might be doing that.

  • #5
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    You're exactly right! I spent 8 hours last night trying to figure this one out, and finally found a way around it. It turned out Flex was adding the time (or CF), and i used this code to rectify the problem, so if anyone else is having trouble... here's the answer

    Code:
    <mx:Script>
     	<![CDATA[ 
    private var myDate:Date;
    
    private function init():void
    {
            myDate = data.Date; // this is the date from the database, i'm using this in a list control with an item renderer to this component
     	myDateLablel.text=DateDisplay.format(myDate);
    {
    
     	]]>
     </mx:Script>
    
    <mx:DateFormatter id="DateDisplay" formatString="DD MMMM YYYY"/>
    
    <mx:Label x="10" y="10" text="{myDate}" id="myDateLabel" />
    Hope this helps, and thanks for the replies
    Last edited by loki421; 06-11-2009 at 01:00 PM.


  •  

    Posting Permissions

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