Getting a date-variable from a post and reformatting to yymmdd
Hello.
I'm new to Umbraco, and have learned how to make document-types, templates and contents to work togheter, thank to our teacher Robert. I now want to change the format by which a date is printed. I get format mm/dd/yyyy - but I want YYYY-dd-mm like 2016-06-08. I don't know how to get the post's (it's a blog post) UpdateDate and how to reformat it. Can you help?
I have this code now for a post (template):
Getting a date-variable from a post and reformatting to yymmdd
Hello. I'm new to Umbraco, and have learned how to make document-types, templates and contents to work togheter, thank to our teacher Robert. I now want to change the format by which a date is printed. I get format mm/dd/yyyy - but I want YYYY-dd-mm like 2016-06-08. I don't know how to get the post's (it's a blog post) UpdateDate and how to reformat it. Can you help? I have this code now for a post (template):
@Convert.ToDateTime(@Umbraco.Field("updateDate").ToString()).ToString("YYYY-dd-mm")
Hi,
Similar to above how I handle this is I usually create a class for my Umbraco documents.
My class would have a date property.
E.g
I would then have a method that pulls through all my umbraco data and assigns it to my class properties.
E.g
You might want to do some null checks etc. I personally usually use a nullable date in my class DateTime?
When it comes to displaying my data to the frontend I usually do this using razor script. You can simply use the date format like above.
E.g.
Hope this helps
Kind Regards
David
is working on a reply...