Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-05-2015, 07:49 AM   #1
StillReading
Enthusiast
StillReading began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Sep 2014
Device: none
Custom column: "pubdate" and "ifempty"

I've been using code like "{languages:ifempty(-)}" in a custom combined column successfully. I've been trying a similar approach for a custom formatted "pubdate", but I can't figure out the correct syntax. Could someone give me a simple example please? I'm not a "real" coder, so the Calibre manual is much too complicated for me... I'd like to have the pubdate formatted as "MMM yyyy", with a "-" character if the field is empty (= no pubdate set). Date formatting works fine ("{:'format_date(raw_field('pubdate'),'yyyy')'} "), and "ifempty" works fine, too - I just don't know how to combine the functions properly.

EDIT: solved the problem by creating another custom column which stores the formatted pubdate. I'd still be interested in knowing if there's a way to get the formatted date without using an additional column.

Last edited by StillReading; 04-05-2015 at 08:03 AM.
StillReading is offline   Reply With Quote
Old 04-05-2015, 05:32 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,772
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
I think that this template does what you want:
Code:
{:'ifempty(format_date(raw_field('pubdate'),'yyyy'), '-')'}
chaley is offline   Reply With Quote
Advert
Old 04-06-2015, 09:56 PM   #3
StillReading
Enthusiast
StillReading began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Sep 2014
Device: none
Thanks, that works beautifully! I've played around a bit with the "{fieldname:|Prefix|Suffix}" syntax and tried to combine that approach with your example, but couldn't get it working properly. Best I got was the formatted pubdate, directly followed by the "raw" pubdate value. I think this is because of improper quoting (I've tried various combinations), or maybe it's not possible to combine two functions.

For anyone playing around with combined fields: I found that if you let Calibre display a combined field as a column in the "grid view", and single click on a row in that column (just like you would when you'd wanted to edit a value), Calibre lets you edit the function directly with a live preview of the result (!). I don't think that functionality is explained in the manual, it's very helpful when playing around with functions.
StillReading is offline   Reply With Quote
Old 04-07-2015, 01:04 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,772
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by StillReading View Post
Thanks, that works beautifully! I've played around a bit with the "{fieldname:|Prefix|Suffix}" syntax and tried to combine that approach with your example, but couldn't get it working properly. Best I got was the formatted pubdate, directly followed by the "raw" pubdate value. I think this is because of improper quoting (I've tried various combinations), or maybe it's not possible to combine two functions.
Without knowing what you tried and what you want to do it is hard to say much. It is very possible that what you want to do is doable only in general program mode, which allows arbitrary function nesting.
Quote:
For anyone playing around with combined fields: I found that if you let Calibre display a combined field as a column in the "grid view", and single click on a row in that column (just like you would when you'd wanted to edit a value), Calibre lets you edit the function directly with a live preview of the result (!). I don't think that functionality is explained in the manual, it's very helpful when playing around with functions.
You can do this without creating a column by using the Template tester. I added it to the context menu for "books in the library" so I can open it on any book with a right-click.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom column not recognized in "Sending books to devices" cheveguerra Devices 4 12-05-2011 01:58 PM
Custom column: "Updated date", when adding new "versions" of the same file? enriquep Library Management 16 11-03-2011 10:46 AM
Sony PRS-T1 and plugboards "tags" from custom column salines Devices 8 10-31-2011 03:00 AM


All times are GMT -4. The time now is 11:58 AM.


MobileRead.com is a privately owned, operated and funded community.