DCSIMG
DateTime Format in Report Builder’s Report Model - Ella Maschiach's BI Blog

Ella Maschiach's BI Blog

BI, Olap Technologies, Tools, System Analysis and Design

News

About Ella Maschiach

Business Inteligence

DateTime Format in Report Builder’s Report Model

I created a Report Model based on a relational DB. I used the autogenerate option. I came to show it to my user, and he noticed that one of the attributes showed just the date, without any time. I looked at the field in my DB and saw that indeed it was of type DateTime and had data about time in it as well as the date. Looking at the format Report Model automatically gave the attribute, I saw the format was “d”.
I remembered that usually I could copy the format I wanted for a field from the format types defined in Excel. So I copied a cell data from the SQL Server table to a sheet in Excel. The format I got from Excel for it was:

dd/mm/yyyy hh:mm 

Thing is, that when I copied that expression to the format property of the attribute in Report Model, it didn’t work. What I got was the day with, at times, a number bigger than 12 after it, and then the year. I also didn’t get an hour after 12 o’clock. The other formats for long time weren’t the representation I was looking for either. So I had to dig a bit deeper…Finally, I understood the DateTime format I needed was actually:

dd/MM/yyyy HH:mm 

This actually comes from the .Net Framework date and time format strings, (and as I admit I don’t know .Net, I didn’t know of these formats before). Apparently, in my first definition the “month” I got before was actually the minutes and the “hour” could only show between 01 and 12 (and not bigger than 12).

So next time I’ll be thinking about formatting a field in Report Builder – I’ll think about .Net format.

Comments

DateTime Format in Report Builder???s Report Model « A Blog for SQL Server Reporting Services (SSRS) Programmers said:

Pingback from  DateTime Format in Report Builder???s Report Model « A Blog for SQL Server Reporting Services (SSRS) Programmers

# June 17, 2010 6:35 AM

stephen carr said:

I've found HH:mm format useful for displaying just time of datetime value.  But one customer wanted to filter patient appointment times so (eg) they could see out-of-hours activity between 18:00 and 08:00.

Even if a field in the Report Model is the HH:mm format it does not allow a filter on time of day as the field behaves like a datetime value in the Report Builder filer dialogue (and assume todays date!).

I've got round this by adding a calculated field to the Report Model “HM” & RIGHT(TEXT(100+HOUR(DateTime)),2) & “:” & RIGHT(TEXT(100+MINUTE(DateTime)),2)

Though a little convoluted it returns values that can be used as a time of day filter e.g. between HM07:00 and HM08:59

The "HM" makes the calculated value behave like a string in Report Builder filtering.  Without alpha characters in the calculated value attempts to filter between 07:00 and 08:59 return vaues filtered between 7 and 8 - not what the user requires.

I hope there's no easier way to do this.

# June 15, 2011 5:32 PM

Ella Maschiach said:

First of all Stephen, thank you for visiting the blog and leaving your insightful comment.

Secondly, I wanted to ask, did you try to create an attribute of “hour” which would be the following expression: Hour(Relevant DateTime) and then apply your filter on that?

Thank you again for your input,

Ella

# June 19, 2011 5:42 PM

stephen carr said:

Ella,

Yes, Hour(datetime) works ok but the user wanted to filter on times of day such as 17:30 to 20:30 (times outside of their 'usual' clinic slots).  Adding a second attribute based on minutes made the filering options very clumsy.

BTW - agree with your observations regarding Report Builder versions 2 and 3 and the relative usability in relation to version 1.0.  My users get along fine with version 1.0 and are very productive (often more so than their colleagues who develop reports based on SQL!) but the interface is such that they almost need to go on a course for the BIDS Report Designer.  Until MS sort out a friendy version (4.0?) of Report Builder I'm staying with version 1.0 but have recently has excellent results with those same users using XL Pivot Tables linked to SSAS data.

Stephen

# June 20, 2011 8:31 PM

Ella Maschiach said:

Hi Stephen,

Maybe try something else? Do you have SQL Server 2008 onwards? If you do, then try the following:

CONVERT(TIME, datetimefield) as tm_fulltime

You can use this field in Report Builder 1.0 as an attribute of data type “time” and set valueselection for the attribute to “none”.

From what I’ve tested on my model, that works as a filter you can write freely into things like 7:02 and so on and it works.

It should work, depending on if you have SQL Server 2008 onwards or not…

As for a replacement for Report Builder 1.0, I totally agree that Excel Pivot tables are a great way to query ad – hoc your data. If you have Excel 2007 onwards, then you can also use their tables (which are also quite smart), the visual aspects and the data mining (see previous posts in this blog on the subject). I understood that the release of Project Crescent in SQL Server 11 should be a sort of replacement, but for now it only works with DAX (which is only in Office 2010 at the moment in PowerPivot). Let’s hope for the best…

Ella

# June 21, 2011 2:59 PM

stephen carr said:

Ella,

Thanks for trying TIME on SQL 2008 - I'll certainly use that when clients move up.

Stephen

# June 22, 2011 1:08 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: