Author Topic: Date formatting  (Read 14240 times)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
i am sure this has come up before but cant find the post.
I have added a function to format date fields
eg.
sortable date:
<Date(<field>,"yyyymmdd">
or to get the year only:
<Date(<field>,"yyyy">
month formatted as 3 char text and year
<Date(<field>,"mmm-yyyy">

it will be in the next update after i have tested it some more

paq

  • Sr. Member
  • ****
  • Posts: 386
Cool, thanks! I for one wished for it :)

Two questions:

1. Will <Date(<Year>,"mm")> be null when a month is not defined in the tag <Year>? That is, can we use <IsNull(<Date(<Year>,"mm")>,true,false)> to see how defined a date is? :)

2. Are h, m and s also available for hours, minutes and seconds when these are defined?


Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
month and day would be 1 for just a year
h and s are supported. For m, m by itself will be ok for minutes, but if you use mm; mmm; or mmmm they get mapped to MM; MMM; MMMM
reason being is because i think most people will try and use mm and end up getting minutes because they dont know about the capitalisation
i guess it could map "n" to "m" but i didnt think people would be interested to format the time over and about the windows default
Last Edit: July 19, 2012, 06:24:53 AM by Steven

Zak

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 2450
Are h, m and s also available for hours, minutes and seconds when these are defined?
You record the time an album is released down to the seconds?! I thought I was nitpicky about tagging!  :D
Bee excellent to each other...

Roadrunner

  • Sr. Member
  • ****
  • Posts: 373
For m, m by itself will be ok for minutes, but if you use mm; mmm; or mmmm they get mapped to MM; MMM; MMMM
reason being is because i think most people will try and use mm and end up getting minutes because they dont know about the capitalisation
i guess it could map "n" to "m" but i didnt think people would be interested to format the time over and about the windows default
Shouldn't "m" be used for the month without leading zero, i.e. 1, 2, 3, ... 10, 11, 12 (in contrast to "mm": 01, 02, 03, ... 10, 11, 12)?

Maybe another approach could be, to say, if "m" or "mm" follows directly "h" (apart from constants like ".", ":") or will be followed directly by an "s" (not sure, if this 2nd case will be necessary"), then it stands for minutes. In all other cases for months. So, you just could define "d.mm.yyyy h:mm:ss", "yyyy-mm-dd hh.mm", "h.mm", "m:ss" or whatever.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
i forgot about a single m so will include that as well.
for the time component i dont want to spend time building complicated parsing to support hours and minutes unless someone can come up with a very good reason why they would want to format hours and minutes differently from the windows settings

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313

paq

  • Sr. Member
  • ****
  • Posts: 386
Are h, m and s also available for hours, minutes and seconds when these are defined?
You record the time an album is released down to the seconds?! I thought I was nitpicky about tagging!  :D
Yeah, to be absolutely sure they appear in the right order ;) Just kidding, was asking out of curiosity since you can format tags like <Date added> where seconds are defined :) So no need to put in the extra effort in this function for me!


The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1269
@Steven, although not a standard DateTime custom format string, is there an undocumented way to use the $Date() function to return the day of the week as a number? Mon == 1, Tue == 2, etc.?


Orin

  • Newbie
  • *
  • Posts: 2
this link has all the valid values
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

This was extremely helpful! I spent a long time formatting am/pm but it turns out I could just use 'tt'; so much simpler 😁

If anyone else is looking for the full list of date/time formatting, this is an excellent reference.