views:

63

answers:

3

Does anyone know how to get actionscript to render a null date value '000:00:00T00:00:00'? I am calling a web service that expects date fields in the SOAP xml. I need some of these dates to serialize as null and I can't see how to produce null. The closest value I can get is '1899-11-30T00:00:00Z'. Below is the code I am using:

var dateStr:String = "0000-00-00T00:00:00+"; var emptyDate:Date = DateUtil.parseW3CDTF(dateStr); newReqData.DateTimeInit = emptyDate;

A: 

You can probably do it with a date formatter. You'll have to create a Date object but if you pass it to the DateFormatter, you can set the format to pretty much whatever you like. Here's the reference and I would recommend looking at the "Other Text" area:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/formatters/DateFormatter.html

Shawn Yale
The problem I am having is not with formatting, it is with the serialization. I want the SOAP call to render the universal NULL date, which I believe is '0000-00-00T00:00:00'. My .Net implementation of this web service call renders this value in the XML post. The Flex implementation does not. It renders '1899-11-30T00:00:00Z'. So the end result is that I get a date of '11/30/1899' in the database which is not desireable. With the .Net implementation, I get a nice NULL in the database.
Jim
I've run into Date type conversion problems before with .Net. Many of these actually come from the start date each system (.Net and Flex) use as a base. I've never actually come across a need to pass a NULL date object(and can't really think of how/why I would need to). If your .Net is inserting a NULL value into the db, perhaps passing it as a NULL from Flex isn't the best approach. Either that or you could check for the 1899 value and simply handle it server-side.
Shawn Yale
You could also try passing a string from Flex and parsing it into a date server-side. Just out of curiosity, if the value is NULL from Flex, why are you passing it at all?
Shawn Yale
I am calling a web service provied by a commercial product, so I have no control in changing it on server side. The WSDL, which I have no control over expects a 'date' type, so I can't pass it a string. (tried that) The WSDL exposes data structures which I am populating and handing back as parameter in service method. The data structure has many date fields. (about 15) In my .Net project which calls this same web service, I don't populate the date fields and the SOAP xml renders this NULL date value that I eluded to earlier. And a NULL results in the DB. Flex forces me to populate the date.
Jim
I totally understand and it's a tough position. Have you looked into WebOrb.net? I haven't dug into it, but there might be something there that can help. Unfortunately, the Date base class in Flex is final so you can't extend it. I tried several approaches and, much like you, I was only able to get back to 1899. I'll keep digging around, but I'm at a loss on this one.
Shawn Yale
We are thinking that the solution may be to create a trigger in the database that changes the Flex date of '1899-11-30T00:00:00Z' to a NULL value. This is 'clugy' but will solve our problem.
Jim
A: 

var d:Date=new Date(); d.setTime(-62167226400000); Alert.show(d.toString());

or as said Shawn Yale, read this.

Eugene