Use UNIX time stamp with date filed

Hi.
I tried to put a UNIX time stamp in to a date filed but that did note work so well, the field in the panel showed 1970-01-01. Does any one know if it is possible to get this to work?

Why do you need to put a unix timestamp in a date field? Would make more sense to use another type of field in that case? Or is a UNIX timestamp what you want as output?

In that case, just using $page->date() will output a Unix timestamp from the date entered into the date field.

Im pretty sure the UNIX time is in a full ISO format format complete with a time zone. I don’t think the time & date fields are expecting that format.

You can go the other way though, and convert the date field to a another format in your template, for example:

$kstartdate = $kcalendarData->startdate();
$kstarttime = $kcalendarData->starttime();
$kenddate = $kcalendarData->enddate();
$kendtime = $kcalendarData->endtime();
$kstartisoDate = date('Y-m-d\TH:i:s', strtotime("$kstartdate $kstarttime"));
$kendisoDate = date('Y-m-d\TH:i:s', strtotime("$kenddate $kendtime"));

Change startdate() etc to the name of your fields. And yeah theres alot of variables going on there, but i needed fine grained control. You can slim it down for your needs.

The thing is that I get a UNIX time stamp form a API and I want to store it in a field. I later need to compare this saved time stamp with a new one from the same api to see if I should run som imports. And I just thought it would be nice to have the panel format the UNIX time stamp in a more human readable way. And If I need to manually change the time stamp it would also be easier to use the date picker to get the right stamp.

The date picker does not support anything more precise than day/month/year, so it does not really make sense to modify a UNIX timestamp via the picker as you would loose information. The date time field would be more appropriate, but I’m not sure you can have seconds in it.

When saving programmatically from the API, why not store the timestamp in a human readable way in the first place?

What do you mean by imports? Reading your response it kind of seems like your talking about automating something, like a Cron job. Can you not just do it with Cron?

I do it by a cron job, but in that script I grab the saved time stamp from a specific page and use it to compare agains the new time stamp in the api. I have other settings saved on that page so I can use it as settings for my import.

At first I did convert the UNIX time stamp to a more readable way before I saved it but I just thought it would be more safe to leave it as is when comparing agains the new time stamp in the api.

Then I don’t see why the user should be able to modify it at all…?