8 Replies Latest reply on Jun 26, 2012 1:07 PM by Code Girl

    Help! How to Stop Auto Conversion of Dates?


      Hi guys,


           I took a look out there and haven't really found a clear answer to this problem. 


           Quite simply, a date field in our MSSQL DB has a timestamp of '2012-06-25 11:54:30.000'


           Our Flex UI is using a Remote Object call via BlazeDS to get that date. I put a small alert in to pull the data from the first row of the blaze returned array to see what the value is...when it comes across, it comes in as: Mon Jun 25 06:54:30 GMT-0500 2012.  Then to make matters worse, label function / date formatters don't do anything about the GMT...it ends up displaying the time "06:54 am" in the receiving data grid. 


           How can I stop this auto conversion to GMT? It's causing all kinds of headaches.  I've considered putting in a date handler but the challenge is that we use many,  many dates across 50+ widgets in our system...and on some of those, for a datagrid for example, we aren't even defining the columns...just the grid and letting the arrayCollection pop the columns. 


           Is there ANY way to stop this auto conversion that is happening? And, if not, what is the best way for me to deal with this? Is there a setting on a dateFormatter that I can use to fix this?




        • 1. Re: Help! How to Stop Auto Conversion of Dates?
          Code Girl Level 1

          Does your tables require TimeStamp.  MSSQL does have other date types.  Timestamp was designed to be just that, a time stamp for display purposes.

          • 2. Re: Help! How to Stop Auto Conversion of Dates?
            Code Girl Level 1

            One other thing, And I am sure you already know this but Timestamp is a subclass to Util.Date.  And normally when converting you use getTime and setTime.  I do not use Blaze and so I am only touching all the basic bases.  Sorry.

            • 3. Re: Help! How to Stop Auto Conversion of Dates?
              stickamw Level 1

              Hi Code Girl,


                   The table requires a dateTime type.  We need the singular date and time field as that is how we get the data from our 3rd party data collectors.  The flex UI is just pulling the dates from the database for display purpose. 



              • 4. Re: Help! How to Stop Auto Conversion of Dates?
                Code Girl Level 1

                You probably need to post some code.  Here is mine in a datagrid.  BTW, this is not all that clean either.




                   <mx:DataGridColumn id="startDateDC" headerText="Start Date" dataField="startDate" width="150"





                      <mx:Canvas width="100%">


                        <mx:DateFormatter id="timeFormatter" formatString="L:NN A"/>

                        <mx:RegExpValidator id="startTimeValidator" source="{timeField}" property="text"

                             expression="^((0?[1-9]|1[012])(:[0-5]\d)(\ [AP]M))$"




                       <s:HGroup width="100%">




                          protected function timeFormat(date:Date):String


                           return timeFormatter.format(date);



                          public function get value():Date


                           var date:Date = new Date(startDateField.selectedDate.toDateString() + " " + timeField.text);

                           return date;



                          protected function startDateField_focusOutHandler(event:flash.events.FocusEvent):void


                           if (outerDocument.nonAvailDto.endDate.time < value.time)


                            outerDocument.nonAvailDto.endDate = value;






                        <mx:DateField id="startDateField"  editable="true" width="50%"




                        <mx:TextInput id = "timeField" editable="true" width="50%"









                • 5. Re: Help! How to Stop Auto Conversion of Dates?
                  stickamw Level 1

                  Here are the pertinent code and examples for yáll:


                  The defenition of the column in the database. I've also selected the row to show what the values coming across are.  Take specific notice of the time in the Date_Time field:



                  Next, here is the datagrid definition and the data return handler with alert code:


                  <mx:DataGridColumn width="150" headerText="Date / Time" dataField="date_time" labelFunction="formatDate"/>


                  private function handleResult(event: ResultEvent):void


                  events = new ArrayCollection; 

                  events = event.result as ArrayCollection;

                  alert.info("First Row Data: ID=" + events[1].event_id + "  || Date = " + events[1].date_time);



                  Finally, here is the alert that is generated on the data return before I do any kind of processing on it:



                  Now what appears to be happening here is that either the Blaze DS or the Flash Player is seeing the 11:54:30 timestamp from the DB and thinks thats in GMT...so for me (in CST) it's taking the 5 hours off it and converting it to 6:54:30....which is WAY wrong.  The timestamp in the DB is actually already in CST.  I have no idea why this conversion is happening but I need it to stop. 






                  • 6. Re: Help! How to Stop Auto Conversion of Dates?
                    stickamw Level 1

                    Ok, for somoe reason, the forum didn't post my images so here's what they contained:


                    DB Definition:


                    Date_Time(datetime, not null)


                    select * from <table> where eventlogid = 111165




                    1111651nn.nn.nn.nnabcd16957712nm2012-06-25 11:54:30.000somoe error message1
                    ccmsuser2012-06-25 11:55:28.850


                    Finally, the alert generates this:


                    First Row Data: ID=111165  || Date = Mon Jun 25 06:54:30 GMT-0500 2012

                    • 8. Re: Help! How to Stop Auto Conversion of Dates?
                      Code Girl Level 1

                      I googled BlazeDS timestamp issues


                      It looks like when you do the transer of data with Blaze, you need to get the timezone first and then set it before you do the transfer.  It appears when using Blaze and timestamp, Blaze assumes you have not converted your timestamp yet and converts it based upon the set timezone.  Since in your case the time is already adjusted, you have two choices.  Set your system which saves the data to save the data unadjusted or tell Blaze your in a timezone which does not adjust.  Which I suspect would be Greenwich Germany.  Therefore, Blaze would not adjust the time.




                      Actually, this one indicates Flash Might be the culprit.


                      http://cookbooks.adobe.com/post_How_is_time_zone_handled_when_using_Remoting_of_Bl-12168.h tml