Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS

Formatting Date


Reply

4 Posts   1159 Views

Avatar
eddieconnecti

27 January 2010 at 12:30pm Community Member, 26 Posts

SS stores Datetime like '2008-06-21 20:30:00' not as timestamp in mySQL Database. I checked this with phpMyAdmin. If I use following code, it results in "01.01.1970", no matter what date I use. Does anyone have an idea how to get a dateobject out of this string? I would prefer not to use explode, I think there must be a php function to do it. I checked the sapphire api and they also use strtotime... No clue...

Example of code:

$starttime = strtotime( $this->start );
$dateTip = date( 'd.m.Y', $starttime );

Avatar
Willr

27 January 2010 at 1:09pm Forum Moderator, 5511 Posts

Well if your field is a SSDateTime field in the database when you do $this->dbObject('FieldName') in the PHP or $FieldName in the templates it returns the full object so you can call the various methods etc.

Avatar
eddieconnecti

28 January 2010 at 9:09am Community Member, 26 Posts

Sorry, doesn´t work. See, I use Datetime:

   public static $db = array(
      "Start" => "Datetime",
      "End" => "Datetime"
   );

Should I better use SSDatetime? If I change the field, do I loose already stored dates? Do I have to write them all again?

But I think, your solution with

$starttime = $this->dbObject( "start" );

should also work with MySQL Datetime...? Maybe I made a mistake, but where...

Avatar
eddieconnecti

15 February 2010 at 11:00am Community Member, 26 Posts

To close this thread I will tell you what finally did it:

I changed DateTime to SSDateTime and left all other code as is. It works now. Best of it: I did not have to change one single date in the database.