For an activity doctype, I use a datetime picker for the start- and enddate. However, my customer needs the possibility to not show time data for some activities.
I tested out your solution, and I noticed that a Date object has a TimeofDay property, which is set to "00:00:00" when no time is chosen with the Datetime picker.
@Jeavon, sorry, my latest post crossed with your solutions. We both used the TimeofDay property in our solutions, but as your where first I'm checking your solution as solved.
@Jeavon, thanks Jeavon, I refactored my code base on your example. I also added a check to see if start- and enddate are on the same day. If they are, the date is only shown once, like this:
14/03/2014 09:00 AM - 04:00 PM
My code looks like this now:
@if (activity.HasValue("activityStartDate"))
{
var startDate = activity.GetPropertyValue<DateTime>("activityStartDate");
var startDateMask = "dd/MM/yyyy hh:mm tt";
<p>
<i class="icon-calendar"></i>
@if (startDate.TimeOfDay == new TimeSpan(0))
{
startDateMask = "dd/MM/yyyy";
}
<text>@(activity.GetPropertyValue<DateTime>("activityStartDate").ToString(startDateMask))</text>
@if (activity.HasValue("activityEndDate"))
{
var endDate = activity.GetPropertyValue<DateTime>("activityEndDate");
var endDateMask = "dd/MM/yyyy hh:mm tt";
if (endDate.Day == startDate.Day)
{
endDateMask = "hh:mm tt";
}
if (endDate.TimeOfDay == new TimeSpan(0))
{
endDateMask = "dd/MM/yyyy";
}
<text>- @(activity.GetPropertyValue<DateTime>("activityEndDate").ToString(endDateMask))</text>
}
</p>
}
Datetime picker, only show time when not 00:00:00
Hi,
For an activity doctype, I use a datetime picker for the start- and enddate. However, my customer needs the possibility to not show time data for some activities.
My code for the moment looks like this:
Is there a way not to show time one an activity item, for example when time is set to 00:00:00, or something similar?
thanks for your help,
Anthony
Hi Anthony,
May be you can get this working
Hi Anthony,
I use C# Date comparison and it would be something like this (I'm assuming you are using MVC or a Macro Partial View here
Jeavon
Perhaps slightly more concise would be:
Hi Fuji,
I tested out your solution, and I noticed that a Date object has a TimeofDay property, which is set to "00:00:00" when no time is chosen with the Datetime picker.
So I came up with this solution which works fine:
@Jeavon, sorry, my latest post crossed with your solutions. We both used the TimeofDay property in our solutions, but as your where first I'm checking your solution as solved.
thanks,
Anthony
Awesome, I would probably perfer to compare DateTime objects rather than strings but they should give the same result.
e.g.
@if (startDate.TimeOfDay.ToString() != "00:00:00")
vsif (startDate.TimeOfDay == new TimeSpan(0))
@anthony no worries , i myself didnt try it before but thanks @jeavon.
@Jeavon, thanks Jeavon, I refactored my code base on your example. I also added a check to see if start- and enddate are on the same day. If they are, the date is only shown once, like this:
My code looks like this now:
That looks great to me!
is working on a reply...