INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: [Expressions 101] How to Create a Custom Date Field  (Read 3770 times)

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
[Expressions 101] How to Create a Custom Date Field
« on: May 10, 2010, 02:37:50 am »

The instructions below will allow you to enter a date one way and than have it displayed anyway you like.

Enter date:


Display it the way you want:


and more...

It also has some features that will help to make sure you enter the date correctly.

After creating this, I stopped using the default date field due to the fact that the default date field would not display only the year and month. With this, if you only enter the year and month, only the year and month will display.


I've tried to make this as simple as possible so that people who do not understand expressions can use this. All you have to do is follow the directions and paste the codes, listed below, in the expression field to make this work.


1. Custom Fields

Go to "Manage Library Fields" and create 6 custom fields and name them:

   Date: Released
   Date: Released (Display)
   Date: Released (Day)
   Date: Released (Month)
   Date: Released (Month #)
   Date: Released (Year)

Tools > Options > Library & Folders > Manage Library Fields... > Add New Field


Except for "Date: Released" all fields are expression fields. I suggest you make the fields uneditable. In order to make a expression field uneditable:

   1. Go to the field and select "User Data"
   2. Change the "Edit Type" to "Cannot be edited"
   3. Click another field in the list, any field, and than go back to the original field
   4. Select "Calculated data"
   
2. Code:

Enter the following code in the expression field right below "Calculated data"

Date: Released (Day)

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Right([Date: Released],2),00,0),,If(IsRange(Right([Date: Released],2),1-9),Right([Date: Released],1),If(IsRange(Right([Date: Released],2),10-31),Right([Date: Released],2),<ERROR: DAY>))))

Date: Released (Month)

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Mid([Date: Released],5,2),00,0),If(IsEqual(Right([Date: Released],2),Mid([Date: Released],5,2),0),,<ERROR: DAY>),If(IsRange(Mid([Date: Released],5,2),1-12),If(IsEqual(Mid([Date: Released],5,2),01,0),January,)If(IsEqual(Mid([Date: Released],5,2),02,0),February,)If(IsEqual(Mid([Date: Released],5,2),03,0),March,)If(IsEqual(Mid([Date: Released],5,2),04,0),April,)If(IsEqual(Mid([Date: Released],5,2),05,0),May,)If(IsEqual(Mid([Date: Released],5,2),06,0),June,)If(IsEqual(Mid([Date: Released],5,2),07,0),July,)If(IsEqual(Mid([Date: Released],5,2),08,0),August,)If(IsEqual(Mid([Date: Released],5,2),09,0),September,)If(IsEqual(Mid([Date: Released],5,2),10,0),October,)If(IsEqual(Mid([Date: Released],5,2),11,0),November,)If(IsEqual(Mid([Date: Released],5,2),12,0),December,),<ERROR: MONTH>)))

Date: Released (Month #)

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Mid([Date: Released],5,2),00,0),If(IsEqual(Right([Date: Released],2),Mid([Date: Released],5,2),0),,<ERROR: DAY>),If(IsRange(Mid([Date: Released],5,2),1-9),Mid([Date: Released],6,1),If(IsRange(Mid([Date: Released],5,2),10-12),Mid([Date: Released],5,2),<ERROR: MONTH>))))

Date: Released (Year)

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Left([Date: Released],4),0000,0),If(IsEqual(Left([Date: Released],4),Mid([Date: Released],5,2)00,0),,<ERROR: MONTH>),If(IsRange(Left([Date: Released],4),1-9),Mid([Date: Released],3,1),If(IsRange(Left([Date: Released],4),10-99),Mid([Date: Released],2,2),If(IsRange(Left([Date: Released],4),100-999),Mid([Date: Released],1,3),If(IsRange(Left([Date: Released],4),1000-2099),Left([Date: Released],4),<ERROR: YEAR>))))))

Date: Released (Display)

This field is used to display your date. Enter one of the following codes in the expression field.

The following examples use the same date:

   Year=2010
   Month=9
   Day=5

1st line tells you the format
2nd line shows you how the date will be displayed if year, month and day is entered
3rd line shows you how the date will be displayed if year and month is entered
4th line shows you how the date will be displayed if only the year is entered
Followed by the code to use if you want your date displayed this way


Month#/Day/Year

   9/5/2010
   9/2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Month #)]),,[Date: Released (Month #)]//)If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]//)[Date: Released (Year)],<ERROR: DATE>))

Year/Month#/Day

   2010/9/5
   2010/9
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),[Date: Released (Year)]If(IsEmpty([Date: Released (Month #)]),,//[Date: Released (Month #)])If(IsEmpty([Date: Released (Day)]),,//[Date: Released (Day)]),<ERROR: DATE>))

Year-Month#-Day

   2010-9-5
   2010-9
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),[Date: Released (Year)]If(IsEmpty([Date: Released (Month #)]),,-[Date: Released (Month #)])If(IsEmpty([Date: Released (Day)]),,-[Date: Released (Day)]),<ERROR: DATE>))

Month#/Day/Year

   9-5-2010
   9-2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Month #)]),,[Date: Released (Month #)]-)If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]-)[Date: Released (Year)],<ERROR: DATE>))

Day Month Year

   5 September 2010
   September 2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)] )If(IsEmpty([Date: Released (Month)]),,[Date: Released (Month)] )[Date: Released (Year)],<ERROR: DATE>))

Day Month(abbr) Year

   5 Sep 2010
   Sep 2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)] )If(IsEmpty([Date: Released (Month)]),,Left([Date: Released (Month)],3) )[Date: Released (Year)],<ERROR: DATE>))

Month Day, Year

   September 5, 2010
   September 2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Month)]),,[Date: Released (Month)] )If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]/, )[Date: Released (Year)],<ERROR: DATE>))

Month(abbr) Day, Year

   Sep 5, 2010
   Sep 2010
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Month)]),,Left([Date: Released (Month)],3) )If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]/, )[Date: Released (Year)],<ERROR: DATE>))

3. How to use the custom Date field

"Date: Released" is used to enter the date. Date field must be ten characters long. Date field must be in the following format:

   yyyy-MM-dd


"yyyy" is the year, it must be a four digit number, between 0000-2099.

Followed by "-" as a separator

"MM" is the month, it must be a two digit number, between 00-12.

Followed by "-" as a separator

"dd" is the day, it must be a two digit number, between 00-31.


Correct way to enter the date:

   2010-01-21
   0500-00-00
   1948-05-00
   0000-00-00


Incorrect way to enter the date:

   2009-10-5
   2010-1-21
   1835-00-19
   0000-12-01
   1948-05
   1948-5
   1999
   500


Error message will always display in the "Date: Released (Display)" field. Error message will appear if you do the following:

   If the date is not 10 characters long. Example: 1987-5-22
   If you do not use the dash (-) as a separator. Example: 2010/05/10
   Enter a year not in range. Example: 2150-05-09
   Enter a month not in range. Example: 1999-13-05
   Enter a day not in range. Example: 1999-05-50
   Enter day but no month. Example: 1947-00-02
   Enter month but no year. Example: 0000-15-00



4. Changing the field name:

Please read carefully

If you don't like the field name I used it is easy to change them using a simple text editor. Start Notepad,
select my entire post and copy/paste to Notepad. Click Edit>Replace or Ctrl+H to use the Replace tool.

Replace "Date: Released" with your own name but keep the suffix:

If you want to change the name to "Recorded"

Type in Find what: Date Released
Type in Replace with: Recorded
Press "Replace All" button
Read and follow the directions in Notepad

This will result you creating the following fields

   Recorded
   Recorded (Display)
   Recorded (Day)
   Recorded (Month)
   Recorded (Month #)
   Recorded (Year)


Change name to something completely different

You MUST find and replace each field name with the desired field name but you MUST find and replace the "Date: Replaced" field last.

So find and replace:

   Date: Released (Display)
   Date: Released (Day)
   Date: Released (Month)
   Date: Released (Month #)
   Date: Released (Year)
   
Than find and replace:

   Date: Released


5. Change how the date is displayed:

Just ask and I'll post the code.



If you find any errors please let me know.
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #1 on: May 10, 2010, 02:49:45 am »

6. Code Breakdown

Below are all the code used to make my custom date field. It is written in a way for easy reading. At least to me.


Date: Released (Day)

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Right([Date: Released],2),00,0)
,
,
If(
IsRange(Right([Date: Released],2),1-9)
,
Right([Date: Released],1)
,
If(
IsRange(Right([Date: Released],2),10-31)
,
Right([Date: Released],2)
,
<ERROR: DAY>
)
)
)
)


Date: Released (Month)

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Mid([Date: Released],5,2),00,0)
,
If(
IsEqual(Right([Date: Released],2),Mid([Date: Released],5,2),0)
,
,
<ERROR: DAY>
)
,
If(
IsRange(Mid([Date: Released],5,2),1-12)
,
If(IsEqual(Mid([Date: Released],5,2),01,0),January,)
If(IsEqual(Mid([Date: Released],5,2),02,0),February,)
If(IsEqual(Mid([Date: Released],5,2),03,0),March,)
If(IsEqual(Mid([Date: Released],5,2),04,0),April,)
If(IsEqual(Mid([Date: Released],5,2),05,0),May,)
If(IsEqual(Mid([Date: Released],5,2),06,0),June,)
If(IsEqual(Mid([Date: Released],5,2),07,0),July,)
If(IsEqual(Mid([Date: Released],5,2),08,0),August,)
If(IsEqual(Mid([Date: Released],5,2),09,0),September,)
If(IsEqual(Mid([Date: Released],5,2),10,0),October,)
If(IsEqual(Mid([Date: Released],5,2),11,0),November,)
If(IsEqual(Mid([Date: Released],5,2),12,0),December,)
,
<ERROR: MONTH>
)
)
)


Date: Released (Month #)

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Mid([Date: Released],5,2),00,0)
,
If(
IsEqual(Right([Date: Released],2),Mid([Date: Released],5,2),0)
,
,
<ERROR: DAY>
)
,
If(
IsRange(Mid([Date: Released],5,2),1-9)
,
Mid([Date: Released],6,1)
,
If(
IsRange(Mid([Date: Released],5,2),10-12)
,
Mid([Date: Released],5,2)
,
<ERROR: MONTH>
)
)
)
)


Date: Released (Year)

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Left([Date: Released],4),0000,0)
,
If(
IsEqual(Left([Date: Released],4),Mid([Date: Released],5,2)00,0)
,
,
<ERROR: MONTH>
)
,
If(
IsRange(Left([Date: Released],4),1-9)
,
Mid([Date: Released],3,1)
,
If(
IsRange(Left([Date: Released],4),10-99)
,
Mid([Date: Released],2,2)
,
If(
IsRange(Left([Date: Released],4),100-999)
,
Mid([Date: Released],1,3)
,
If(
IsRange(Left([Date: Released],4),1000-2099)
,
Left([Date: Released],4)
,
<ERROR: YEAR>
)
)
)
)
)
)


Date: Released (Display)

9/5/2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
I sEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Month #)]),,[Date: Released (Month #)]//)
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]//)
[Date: Released (Year)]
,
<ERROR: DATE>
)
)


2010/9/5

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
[Date: Released (Year)]
If(IsEmpty([Date: Released (Month #)]),,//[Date: Released (Month #)])
If(IsEmpty([Date: Released (Day)]),,//[Date: Released (Day)])
,
<ERROR: DATE>
)
)


2010-9-5

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
[Date: Released (Year)]
If(IsEmpty([Date: Released (Month #)]),,-[Date: Released (Month #)])
If(IsEmpty([Date: Released (Day)]),,-[Date: Released (Day)])
,
<ERROR: DATE>
)
)


9-5-2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Month #)]),,[Date: Released (Month #)]-)
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]-)
[Date: Released (Year)]
,
<ERROR: DATE>
)
)


5 September 2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)] )
If(IsEmpty([Date: Released (Month)]),,[Date: Released (Month)] )
[Date: Released (Year)]
,
<ERROR: DATE>
)
)


5 Sep 2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)] )
If(IsEmpty([Date: Released (Month)]),,Left([Date: Released (Month)],3) )
[Date: Released (Year)]
,
<ERROR: DATE>
)
)


September 5, 2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Month)]),,[Date: Released (Month)] )
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]/, )
[Date: Released (Year)]
,
<ERROR: DATE>
)
)


Sep 5, 2010

Code: [Select]
If(
IsEmpty([Date: Released])
,
,
If(
IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0)
,
If(IsEmpty([Date: Released (Month)]),,Left([Date: Released (Month)],3) )
If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]/, )
[Date: Released (Year)]
,
<ERROR: DATE>
)
)
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #2 on: May 10, 2010, 02:46:42 pm »

I found an error in my coding. :( This has to do with all the codes under "Date: Released (Display)". I've fixed it and updated my post.  ;D
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #3 on: May 10, 2010, 04:52:59 pm »

Updated codes under "Date: Released (Display)" again. I'm pretty sure I got all the bugs out this time.  ::)

Below is the list of code changes.

Year/Month#/Day

   2010/9/5
   2010/9
   2010

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Length([Date: Released])Mid([Date: Released],4,1)Mid([Date: Released],7,1),10--,0),If(IsEmpty([Date: Released (Year)]),,[Date: Released (Year)])If(IsEmpty([Date: Released (Month #)]),,//)If(IsEmpty([Date: Released (Month #)]),,[Date: Released (Month #)])If(IsEmpty([Date: Released (Day)]),,//)If(IsEmpty([Date: Released (Day)]),,[Date: Released (Day)]),<ERROR: DATE>))
Logged

gappie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 4583
Re: [Expression 101] How to create a custom date field
« Reply #4 on: May 10, 2010, 05:10:20 pm »

that is a nice piece of work. very educational.

what i was wondering. have you tried to accomplish the same using something like
listitem([date: released], 0,-)
to get for instance year,
listitem([date: released], 1,-)
for month
instead of all the remove and mid statements. was thinking it might end up shorter, but i might be wrong. maybe a listitem([date: released],-) to see if the dates are complete.

great post

 :)
gab
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #5 on: May 10, 2010, 05:35:20 pm »

Updated every code under "Date: Released (Display)" AGAIN ::) cut out unneeded code
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #6 on: May 10, 2010, 06:02:10 pm »

that is a nice piece of work. very educational.

what i was wondering. have you tried to accomplish the same using something like
listitem([date: released], 0,-)
to get for instance year,
listitem([date: released], 1,-)
for month
instead of all the remove and mid statements. was thinking it might end up shorter, but i might be wrong. maybe a listitem([date: released],-) to see if the dates are complete.

great post

 :)
gab

Wow, I didn't know I could use ListItem like that. Thanks for the info.

As to the code ending up being shorter, I have no idea. I'd have to rewrite the code with ListItem and compare. But first I need to play around with ListItem a bit.
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #7 on: May 11, 2010, 04:59:15 pm »

Corrected the "Date: Released (Year)" code. Top post has been updated. Error would display if the year was set to 0000.

Date: Released (Year)

Code: [Select]
If(IsEmpty([Date: Released]),,If(IsEqual(Left([Date: Released],4),0000,0),If(IsEqual(Left([Date: Released],4),Mid([Date: Released],5,2)00,0),,<ERROR: MONTH>),If(IsRange(Left([Date: Released],4),1-9),Mid([Date: Released],3,1),If(IsRange(Left([Date: Released],4),10-99),Mid([Date: Released],2,2),If(IsRange(Left([Date: Released],4),100-999),Mid([Date: Released],1,3),If(IsRange(Left([Date: Released],4),1000-2099),Left([Date: Released],4),<ERROR: YEAR>))))))
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expression 101] How to create a custom date field
« Reply #8 on: May 15, 2010, 10:59:16 pm »

that is a nice piece of work. very educational.

what i was wondering. have you tried to accomplish the same using something like
listitem([date: released], 0,-)
to get for instance year,
listitem([date: released], 1,-)
for month
instead of all the remove and mid statements. was thinking it might end up shorter, but i might be wrong. maybe a listitem([date: released],-) to see if the dates are complete.

great post

 :)
gab

I rewrote a few codes and compared them and it seems it's shorter using the mid,right & left. Mostly due to the fact that listitem has more letters.
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expressions 101] How to Create a Custom Date Field
« Reply #9 on: May 16, 2010, 12:34:02 am »

Added a section where I broke down the code for easy reading.

Made a correction to "Date: Released (Day)" code.

Added another "Date: Released (Display)" code.

Changed all the codes under "Date: Released (Display)" again because I got a phantom space appearing in front of the year, if only the year was displayed. Found out it was some bug that corrected itself with a restart of MC. But by then I had already changed all the codes and didn't feel like changing it back.

Updated directions to be clearer.
Logged

drc

  • World Citizen
  • ***
  • Posts: 115
Re: [Expressions 101] How to Create a Custom Date Field
« Reply #10 on: May 19, 2010, 05:16:04 pm »

I have a similar problem with customized fields.  I'm using MP3 Tag editor to input my data.  I've created a few customized field which has worked nicely.  however, there 's one field I can not get to populate.

Mixartist.


The info shows in the Mp3 Editor fields, but it doesn't show in the MC 14 field.

I've created several different variations (Mixed Artist, My Mixed Artist, etc.) with no success, the value will not show up. 

Not an expert, but I've created a few fields in MC-14 and the data shows up  with no problem.   

Any idea how to create a new link between MP3 Editor and MC-14.
Logged

221bBS

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 703
Re: [Expressions 101] How to Create a Custom Date Field
« Reply #11 on: May 20, 2010, 09:32:11 am »

In order for MC to show a field it must first be in "Manage Library Fields".

Tools > Options > Library & Folders > Manage Library Fields...

If it's not in there you can create it by pressing the "Add New Field" button.

Logged
Pages: [1]   Go Up