Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add DateTime to the new record? #32

Open
Muralik2 opened this issue Aug 1, 2019 · 1 comment
Open

How to add DateTime to the new record? #32

Muralik2 opened this issue Aug 1, 2019 · 1 comment

Comments

@Muralik2
Copy link

Muralik2 commented Aug 1, 2019

I want to add DateTime to newRecord[0] = DateTime.Now;
Which is not working, in valid cast error?

@rossdonald
Copy link

In SPSS DateTime seems to be stored as number of seconds from start of the Gregorian calendar.

So you can use a function like this to calculate the value:

double GetSpssDateTimeValue(DateTime value)
{
	// SPSS uses this date as its zero date
	DateTime epocStart = new DateTime(1582, 10, 14, 0, 0, 0, DateTimeKind.Unspecified);

	return value.Subtract(epocStart).TotalSeconds;
}

Then use code like this to set the variable value:

newRecord[0] = GetSpssDateTimeValue(DateTime.Now);

A datetime variable definition looks something like this

new Variable("StartDate")
{
	Label = "Start",
	Type = DataType.Numeric,
	Width = 20,
	PrintFormat = new OutputFormat(FormatType.DATETIME, 20),
	WriteFormat = new OutputFormat(FormatType.DATETIME, 20),
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants