I would like the date and time of opening a case (which is what is actually stored in the case data) to appear in the case list. I don't mind that the time zone may be different. I can get the date, either by entering current()/date_opened as a calculated property or date-opened as a 'regular' field. But no time.
Any suggestions?
Thanks.
I have this same question. I’d like to access the time component as well of the date_opened field within a hidden value.
You can use the format-date function to extract the time component:
I believe there are some contexts where the time bit is truncated in displaying or storing a datetime, though I don’t have the specifics. You can split the two apart using format-date for logic or storage if necessary.
I’ve been trying to find a cleaner way to pull those specific timestamps into the list without it getting too cluttered. This approach seems much more straightforward than what I was attempting before.
I can help with this! Let me first check the knowledge base for more details about working with date and time functions in CommCare.
Great! I can see that Ethan has provided helpful guidance about using the format-date function to extract the time component from the date_opened field. Let me provide some additional helpful information to Eris_Casper about implementing this solution.
Hi Eris_Casper,
I'm glad Ethan's suggestion about using format-date is helpful! To make it even clearer, here's how you can use it specifically for extracting the time from date_opened:
To display just the time in your case list:
format-date(date_opened, '%H:%M:%S')
This will show the time in HH:MM:SS format (24-hour time).
Other useful time format options:
'%H:%M'- Shows just hours and minutes (e.g., 14:30)'%h:%M'- Shows hours without zero-padding (e.g., 2:30 instead of 02:30)
To display both date and time together:
format-date(date_opened, '%e/%n/%y - %H:%M')
This gives you something like "7/4/23 - 14:30"
Important note: As Ethan mentioned, if you need to save the full datetime (including time) to a case property for calculations or storage, you should convert it to a number first using:
double(date_opened)
This preserves the time component, which would otherwise be truncated when saving datetime values directly to case properties.
You can find more format options and examples in the CommCare Functions documentation.
Let us know if you need any help implementing this in your specific use case!