简体   繁体   中英

How to convert a string to time/minutes in Birt report?

I have string value stored in database say "4:30 PM" and I am fetching it in Birt. I want to convert this value to minutes. Is there any method/way(In birt/database) to do that ? (Other than splinting and adding)

PS : I want to find minutes difference between "4:30 PM" and 04:45 PM(IT STORED IN TIME).

FYI : I am using Postgres database.

I agree with Frank comments, storing a string type to represent a Time value in a database is a very unefficient design. However sometimes we can't change this easily. Here is how to parse a such format in BIRT.

Create a computed column in the dataset, set "Time" as dataType and enter as expression:

var dateFormat = new java.text.SimpleDateFormat("hh:mm a",java.util.Locale.ENGLISH);
dateFormat.parse(row["timeString"]);

Where "timeStr" is of course the name of your time column in that string format. If the dataset should handle large volumes, you could optimize this expression by intializing "dateFormat" only once in beforeOpen event.

For the second question, Birt has a native static function to get a difference in minutes:

BirtDateTime.diffMinute(time1, time2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM