I have used successfull @Umbraco.Field("mydatefield", formatAsDate: true) to format a date the way I would like it to display, however I am have difficulties for child page elements when it is @page.mydatefield. How could I format this properly?
I think is because you are using the data type called datepicker with time, there is also one just called datepicker, and then you should only get the date.
Did you also publish the nodes after you have changed the datatype as datepicker? The XML cache needs to be updated after you have changes a page. So try to publish the event nodes again, or make a republish the entire site. How did you razor code look like for outputting the date?
It works fine with that snippet. Thank you... In case, if it needs to show time only with hours, seconds and AM / PM along with date, how can I do it ?
You can check if a field has a value by using the .HasValue, So I think this codesnippet should do it for you. Or at least gives you some idea on how you can do this.
formatasdate
Hi everyone,
I have used successfull @Umbraco.Field("mydatefield", formatAsDate: true) to format a date the way I would like it to display, however I am have difficulties for child page elements when it is @page.mydatefield. How could I format this properly?
Hi Alex
You should be able to do something like this
@page.mydatefield.Date.ToString("MMMM dd, yyyy")
Does that work for you?
/Jan
Hi Jan and Alex,
I used datepicker datatype in my site for events listing. It shows date with time in page. I need only date..How to do this?
Hi Thomas,
I think is because you are using the data type called datepicker with time, there is also one just called datepicker, and then you should only get the date.
Hope this helps,
/Dennis
Hi Dennis,
I changed the datatype as datepicker. But it shows date with time as 3/20/2014 12:00:00 AM..... the time is binded by default in all event date...
Hi Thomas,
Did you also publish the nodes after you have changed the datatype as datepicker? The XML cache needs to be updated after you have changes a page. So try to publish the event nodes again, or make a republish the entire site. How did you razor code look like for outputting the date?
Hope this helps,
/Dennis
Hi Dennis,
I republished entire site..But it didn't work.... events are listed out from media section....My partial view code is as below,
@{ var mediaFolderId = (int)CurrentPage.NewsMediaFolder; }
@if (mediaFolderId > 0)
{
var mediaFolder = Umbraco.TypedMedia(mediaFolderId);
var newslist = mediaFolder.Children(x => x.DocumentTypeAlias == "News").ToList();
foreach (var news in newslist)
{
<div class="col-md-6 pressmain1">
<div class="col-md-6 pressimgdiv">
<img class="img-responsive" src="@(news.GetPropertyValue<string>("newsimage"))">
</div>
<div class="col-md-6 pressmain2">
<p class="presshead">@(news.GetPropertyValue<string>("newstitle"))</p>
<p class="calender">
<i class="fa fa-calendar calendericon"></i> @(news.GetPropertyValue<string>("newsdate"))</p>
<p class="presscontent">
@(news.GetPropertyValue<string>("newscontent"))
</p>
</div>
</div>
}
}
Hi Thomas,
Okay you are using strongly typed Razor syntax. For outputting the date try to use this snippet
Hope this helps,
/Dennis
Hi Dennis,
It works fine with that snippet. Thank you... In case, if it needs to show time only with hours, seconds and AM / PM along with date, how can I do it ?
for eg., 16-03-2015 04:30 AM
Hi Thomas
Then you write time settings as the parameter like
Hope this helps.
/Jan
Hi Jan,
It works fine now...thank you.
Hi Jan,
I have startdate and enddate for events...I need to display dates when both r given. ( 16-03-2015 to 18-03-2015)
If startdate is only provided, then i need to display start date only. (16-03-2015).
But it shows with default value for enddate ( 16-03-2015 to 01-01-0001 )...How to check enddate has default value ?
Hi Thomas,
You can check if a field has a value by using the .HasValue, So I think this codesnippet should do it for you. Or at least gives you some idea on how you can do this.
Hope this helps,
/Dennis
Hi Dennis,
Okay....it works now..thank you....
is working on a reply...