Monday, March 19, 2012

Formatting Date/Time

What do I have to use to Format my date/time fiels so that they will not include the both the date and the time? I imported the db's and reports from access and anything date/time shows both. The VBA functions I know are powerless to fix this.

So:
Format(fields!DateField, 'hh:mm') ?
Format(fields!DateField, 'ddmmyyy') ?

What are the equivalents? Yes, I read the manual. Still not obvious to me.

- Thanks in advance.

Format is the VB.NET Format function (see e.g. http://msdn2.microsoft.com/en-us/library/59bz1f0h(vs.80).aspx). The following expression should work for you (note: you have to use double quotes not single quotes for the format string):
=Format(Fields!DateField.Value, "hh:mm")

Additional information about datetime format strings is available here:
* http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcustomdatetimeformatstrings.asp
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondatetimeformatstrings.asp

-- Robert

|||Thank you Robert. This works in my .rdl reports. I also want to apply Format to a Parameter which uses a query. I tried to code Format into my SQL as I would with VBA/Jet SQL and it's not working. How can I apply Format to my SQL output or Parameters?|||

Please check the TSQL documentation on the Cast and Convert functions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ca-co_2f3o.asp

-- Robert

No comments:

Post a Comment