July 25, 2005 at 11:05 pm
I have a field in the database that is of DateTime format. So this means that it has, as an example, a value of "7/7/2005 12:30 PM" as its value, but when I try to only get the time part,
"12:30 PM" it errors. The expression I am using is
+Fields!job_date.Value.ToString("hh:mm") it says:
'Public Overridable Function ToString() As String' has no parameters and its return type cannot be indexed.
Any Ideas?
July 25, 2005 at 11:41 pm
Are you sure "Fields!job_date.Value" is being read in your application as a datetime?
--------------------
Colt 45 - the original point and click interface
July 25, 2005 at 11:47 pm
yes it is, but i think ive got it now, i had to use the convert function in my sql to convert it to a time value...
convert(varchar(10),job_date,108) as time
seems to work
July 25, 2005 at 11:52 pm
Well at least it works, but it doesn't really solve your initial problem. The only difference between this
MyString = MyDate.ToString("hh:mm");
and you snippet of code, is that you're refrencing a field.
Oh well, another day perhaps.
--------------------
Colt 45 - the original point and click interface
July 26, 2005 at 12:11 am
yeah, i think it didnt like it inside a text field, because I have parameters in the report and the parameters default values allow the .ToString("dd/Mm/yyyy") function, so i dont know...
July 26, 2005 at 5:46 pm
I found a better way of doing it, if your value from the DB is a DateTime object, you can use the .ToShortTimeString() function on your value in the expression field...works great and saves stupid sql
July 27, 2005 at 1:28 pm
As an example, here's what I use in my report headers:
="Report Generated At " & Globals!ExecutionTime.ToShortTimeString() & " On " & Globals!ExecutionTime.ToLongDateString()
July 30, 2005 at 7:36 am
I would have just edited the format in the properties to be hh:mm tt
Lon
July 31, 2005 at 6:45 pm
oh ok, so in the properties field of the text box, just put in "hh:mm" as the custom formatting??
August 6, 2005 at 7:44 am
You might want to include the tt for AM / PM: "hh:mm tt"
August 7, 2005 at 10:38 pm
thanks all for your replies, I have solved the issue! but i thought i may post something of interest to others:
Sometimes when you have the total minutes for something, it can be tricky to get the hours and minutes formatted correctly,
i.e. 150 minutes as 2:30
so here is some code I use in reporting services to do that:
=string.format("{0:00}:{1:00}", Math.Floor(Fields!total_minutes.Value / 60), Fields!total_minutes.Value mod 60)
there may be better ways to do this, but this is how i do it
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply