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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

formatting date on results of custom query?


Go to End


9 Posts   3115 Views

Avatar
johnofjack

Community Member, 22 Posts

11 November 2011 at 6:09am

Is there a way to format the date in the results of a custom query? I have the date selected from the table as Date, but then in the control on the page where I'm using the query, $Date returns the date in a format I don't want on that page, and things like $Date.Nice and $Date.format(M) all return nothing.

Avatar
Devlin

Community Member, 344 Posts

12 November 2011 at 2:58am

Edited: 12/11/2011 3:00am

$customQueryObj->Date = DBField::create('Date', $customQueryObj->Date);

Avatar
johnofjack

Community Member, 22 Posts

12 November 2011 at 8:26am

I don't understand what you're trying to say. Where are you suggesting I put that?

Avatar
Devlin

Community Member, 344 Posts

12 November 2011 at 9:57pm

Your custom query returns the date as a string. You will need to iterate the results of your query and reapply the date object to your date value before you return the data to the template.

Avatar
cumquat

Community Member, 201 Posts

16 November 2011 at 12:57am

Hi ya,

Not sure if this is what you're after,

when i've got a data object page and i've wanted to get the short month of a date so used

 public function getMonth() { 
		return $this->obj('CalloutDate')->ShortMonth(); 
	}

this then meant i could use $CalloutDate.ShortMonth on the template in the control.

you can do the same for nice.

Mick

Avatar
johnofjack

Community Member, 22 Posts

22 November 2011 at 3:37am

Thanks for the suggestions. I'll look into this and see if I can get it working properly.

Avatar
johnofjack

Community Member, 22 Posts

26 December 2011 at 3:32am

I experimented with this at length, couldn't get it to work, decided to leave it alone awhile, came back to it, still can't get it to work.

Avatar
Mitchell

Community Member, 1 Post

27 December 2011 at 8:45pm

Useful Discussion

Go to Top