DateTime

  • 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?

  • Are you sure "Fields!job_date.Value" is being read in your application as a datetime?

     

    --------------------
    Colt 45 - the original point and click interface

  • 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

  • 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

  • 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...

  • 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

  • As an example, here's what I use in my report headers:

    ="Report Generated At " & Globals!ExecutionTime.ToShortTimeString() & " On " & Globals!ExecutionTime.ToLongDateString()

  • I would have just edited the format in the properties to be hh:mm tt

    Lon

  • oh ok, so in the properties field of the text box, just put in "hh:mm" as the custom formatting??

  • You might want to include the tt for AM / PM:  "hh:mm tt"

  • 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