11 years ago
2
Topic

Hello,


I have a storage problem with a calendar field in one of my content types.

The fields name is news_dat with storage formate Timestamp and the name of the content type is news.

I set storage to Standard -> Article -> news_dat and check the box "Alter" and choose format Timestamp.


Now SEBLOD adds a field to the table cck_core_fields in the DB.

storage_table says #__cck_store_form_news


When I choose a date and save, it doesn't get saved to #__cck_store_form_news.

The value in the DB is 0000-00-00 00:00:00. And the field is empty after saving.


When I set the storage format to Datetime, it is working fine.


How can I get the date saved as timestamp?

Get a VIP membership
310 Posts
ricco
11 years ago
1
Level 1

Hi, after a quick search of: "datetime vs timestamp joomla", I've found this:



"Remember that although DATETIME, DATE, and TIMESTAMP  values all can be specified using the same set of formats, the types do not all have the same range of values. For example, TIMESTAMP values cannot be earlier than 1970 or later than 2037. This means that a date such as '1968-01-01', while legal as a DATETIME or DATE  value, is not valid as a TIMESTAMP value and is converted to 0.

Changing all these values in the *.sql files to 1970-01-01 00:00:01  would solve the problem , I think."


and then the answer:


"Examine what the table structure of one of the tables.  Note that 0000-00-00 00:00:00 is being inserted into columns of type DATETIME, which, from your own quote is legal.

TIMESTAMPs are seconds since unix epoch and that's why they can't be <1970."


all from here:


http://forum.joomla.org/viewtopic.php?p=673888


Regards

Ricco

11 years ago
0
Level 2

Thank you Ricco for taking a look into this.

I understand what you are saying.

The timestamp values get saved as 0000-00-00 00:00:00 in DB because the column they get saved in has format Datetime.

But before it was format timestamp and still the 0000-00-00 00:00:00 got saved instead of the correct timestamp.

As a workaround I am now saving in Datetime format and convert in PHP to timestamp format like this:

$dateobject = new DateTime($cck->getValue('news_dat'));
$timestamp = $termDate->getTimestamp();

This way I can use the timestamp to output the name of the month with:

echo strftime("%B", $timestamp);


I need the name of the month and this was my original reason to save the date in timestamp format to the DB.


Although my workaround solves the problem for me, I will leave the thread as open because I still don't have an answer why timestamp format doesn't get saved correctly to the DB.

Get a Book for SEBLOD