SpssDateVariable "format"

Dec 15, 2010 at 8:35 PM


First, I just wanted to say (again), how much I LOVE this library.  I'm using it in a project to export a LOT of variables and a LOT of cases and it has worked flawlessly so far. A HUGE THANK YOU to the author for putting this together and supporting it on CodePlex.

I have one question right now that I can't seem to find an answer to. When writing a SpssDateVariable, is there a way to specify the "format" of the date? In PASW you would go to the variable and hit the type, then select Date and get a list of possible formats from dd-mmm-yyyy to ddd hh:mm:ss.ss, etc. I'd like to use the standard American mm/dd/yyyy, however I can't seem to find a way to specify this at all through the interop library.  Nor can I find any reference to this in the official SPSS SDK.  I may obviously be looking in the wrong place, so please forgive me if that's the case. I suppose I could get around this by taking my source date time object, parsing it to a string of the format that I desire and re-parse that string back in to a datetime object, but that doesn't seem like a great way to go about this.

Thank you for any input any one can provide!


Dec 16, 2010 at 1:40 AM
I believe the SpssDateVariable properties PrintFormat & WriteFormat may provide what you need.
Dec 16, 2010 at 8:55 PM

Good point, and I think you're correct.

So what I tried to do was the following:

        SpssDateVariable vDOB = new SpssDateVariable();
        vDOB.Name = "DOB";
        vDOB.WriteFormat = FormatTypeCode.SPSS_FMT_ADATE;
        //vDOB.PrintFormat = FormatTypeCode.SPSS_FMT_ADATE;
If I try either the print format, or the write format, or both together, I get an error when I SpssDoc.CommitDictionary();

The error looks like this:

SPSS function spssSetVarWriteFormat returned error code SPSS_INVALID_WRFOR


Any further ideas? This obviously isn't a game breaker for me, but it'd be "nice to have".


Thanks again!

Dec 17, 2010 at 12:20 AM
As I recall, this property (in SPSS) is very picky. Although there are many formats to choose from, only a very few are allowed to be used in this context. I suggest you try each one (yikes) until you find the one that works and that accomplishes what you want. There should be several date-based numeric formats from which to choose.