INTERACT FORUM

Please login or register.

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

Author Topic: ConvertDate(...) and FormatDate(...)?  (Read 1156 times)

javidan

  • Junior Woodchuck
  • **
  • Posts: 76
ConvertDate(...) and FormatDate(...)?
« on: March 23, 2012, 02:57:31 am »

I'm a bit lost trying to use the functions ConvertDate() and FormateDate().

Added the expression function ConvertDate(...) to convert a human readable date to the internal date format (example: ConvertDate(3/6/2012) or FormatDate(ConvertDate(3/6/2012), decade))

May I know what is ConvertDate() expecting? Must your parameter be in the dd/MM/yyyy format?
I used the example "FormatDate(ConvertDate(3/6/2012), decade))" and pasted it into a String field in my tag as

=FormatDate(ConvertDate(3/6/2012), decade))

The result I get is ")" (Without quotes)

Actually, all I am trying to do is use MC to read the first 8 numbers of a filename (using a very common date convention yyyymmdd) and autotag files into their respective Dates/Months/Year within MC.

For example:
20110225 - FileNameAndOthers.pdf
20110522 - AnotherFileNameAndOther.pdf


I tried ConvertDate(Left(FileName(),8)) and I'm getting weird answers.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: ConvertDate(...) and FormatDate(...)?
« Reply #1 on: March 23, 2012, 11:34:01 am »

I'm in the process of updating the wiki on these, and there are some recent not-published changes.  Hang in there for more info...

Re:  FormatDate(ConvertDate(3/6/2012), decade))

There's an extraneous trailing parenthesis, and you'd need to quote the / chars.  Instead, use this to simplify:

   FormatDate(ConvertDate(3-6-2012), decade)

ConvertDate() takes human readable date strings, and converts them to an internal MC representation.
FormatDate() converts an internal MC date representation into a human readable format, with the desired formatting.

You want to grab the date portion from the filename, and send it to ConvertDate so that MC knows it is a date.  Let's start with grabbing the date portion.  Since ConvertDate needs a separator between the year, month, and day, let's do that:

  Regex([Filename (name)], /#^(\d{4})(\d{2})(\d{2})#/, -1)[R1]-[R2]-[R3])

This outputs the date with a dash between year, month, and day.  Now from something like 20110522, we have from 2011-05-22.  This can be handed to ConvertDate(), so let's test:

  ConvertDate(2011-05-22)

returns 40685, an internal MC date representation.  So here's the whole thing:

  ConvertDate(Regex([Filename (name)], /#^(\d{4})(\d{2})(\d{2})#/, -1)[R1]-[R2]-[R3])

You can use this expression to assign to a Date field.
Logged
The opinions I express represent my own folly.

javidan

  • Junior Woodchuck
  • **
  • Posts: 76
Re: ConvertDate(...) and FormatDate(...)?
« Reply #2 on: March 23, 2012, 11:17:47 pm »

OMG,

It just WORKS.

Okay, now I'll have to sit down and spend the next 50 years of my life deciphering what and how the script worked. *laugh*

Thanks. :)
Logged
Pages: [1]   Go Up