How to format date time in SSRS 2008 [duplicate] - sql

This question already has answers here:
How do I format date and time on ssrs report?
(11 answers)
Closed 9 years ago.
I am working with SSRS 2008. I am needing to format the date time. I am currently using this expression
=FormatDateTime(Parameters!startdate.Value)
the output of this expression is
1/22/2014 6:00:00 am.
I would like it to say just
1/22/2014
What would i need to do to this expression to make the output look this way?
Thanks in advance.

try something like
=Format(Parameters!startdate.Value,"dd/MM/yyyy")

You should use the Format property of the Textbox for this and format data in the expression only as a last resort. Select the textbox and look for Format in the property window. There you can enter the format string like dd/MM/yyyy without quotes.
That will keep your expression clean (in fact, you won't need an expression at all) and as an added bonus will allow exporting the value to excel as a datetime so you won't get datetime format conflicts later.
If your datetime is only a part of the text, you can even create a placeholder and put the format on that placeholder. Example textbox:
The time is [#startdate].
When you enter this, [#startdate] becomes a placeholder with your parameter and you can select it and set a format on it. No expressions needed.

Related

Access SQL: Format a calculation as a percentage (Numeric, not string)

I'm working in Access 2010's SQL editor and I'm performing a calculation that results in a ratio.
I would like to display this ratio as a percentage using the SQL syntax editor, but as a number, not a string. I'd like to be able to paste out/export to Excel and not have to convert text to numbers.
Let's say this is my calculation:
OriginCount/DestinationCount AS MatchRate
I used the FORMAT function to make it appear as a percentage, but the result appears as a string. (Which I think is how the FORMAT function is designed to work)
FORMAT(OriginCount/DestinationCount,'Percent') AS MatchRate
Question 1: Is this possible using the SQL syntax editor?
Question 2: How do I do it?
Thanks!
How will you be using this data? It is standard to leave it as a double, EG: 0.02354, and then simply change the format of any control displaying that field.
Users should not being seeing tables or queries without them being the recordsource of a form, so this shouldn't be a problem.
That way, when exporting to Excel/Wherever else, it will properly display as a decimal number, and when viewing in Access, it will display as a Percentage 2.35%
The result of the FORMAT function in access is always in string format, so that would be expected behavior.
Did you try the CONVERT function instead?
https://msdn.microsoft.com/en-us/library/ms187928.aspx

Is it possible to add just Date in a datetime column and not get appended 00:00.000

MY Table consists of a datetime column and I wanted to know if its possible to add just Date in the column without getting appended zeros in Time part. Currently I used
CONVERT(date, getdate()) and tried to insert , but it comes in as
2013-01-20 00:00:00.000 in the column.
Pardon me if this is a very basic question
Yes, it is. Use the DATE data type instead of DATETIME.
However do not concern yourself with whether the 0s are there are not - that's not how SQL Server stores it internally, it's just how Management Studio is presenting it to you.
If you are using SQL Server you could use the Date type rather than DateTime. Otherwise the zeros will be there for the time portion. Of course you can choose not to display the time portion in your application if desired.

Using T-SQL 'Two Digit Year Cutoff' in script

I'm writing a script to cleanup some data, converting dates stored in an varchar field from dd/mm/yy to dd/mm/yyyy format. (yes, I know, but not my design :)
I've got a script written to do this, but I've currently got a hardcoded constant of 2049 as the cutoff date. I know SQL has a 'Two Digit Year Cutoff' advanced option, which I'd like to use in place of this constant.
Is there a safe/convenient way to retrieve and use this in a script?
(Needs to support SQL-Server 2005/2008/2008R2)
SELECT value
FROM sys.configurations
WHERE name = 'two digit year cutoff'
But can't you just convert (assuming that your system is setup to use dd/mm/yyy as a standard) to a datetime, and then back again?

Sorting a time value in a dataset

In my current solution, I am converting a DateTime value, "Time" in my database using CONVERT so it displays in a ##:##AM/PM format, and I realize that CONVERT just takes whatever datatype and turns it into a VarChar, or a String once its in C#. This is making my sort work incorrectly in my Gridview. I am sorting the columns in my DataSet returned from my stored procedure. However it isnt sorting by AM/PM since its a string literal, and not a DateTime.
What is the best way to sort Time values? Should I use a different datatype, like TIME in my database? Different CONVERT command? I'm stumped! I can't use a 24 hour format, that's the only restriction. Thanks!
A couple of thoughts:
Could you use AM 01:23 / PM 01:23 format - this would sort well.
If you can return the times from the database in DATETIME format, but with the date set to some 'constant date' (e.g. 2000-01-01 hh:mm), you could almost certainly put a format string on the GridView column to display just the time, whilst still enabling sorting by the underlying value.
I use ticks: http://www.codeproject.com/KB/database/DateTimeToTicks.aspx
Or (if possible) DateTime - and handle it in my grid.
You can add an additional column with the date/converted date which is hidden in you gui but used to sort.

Input mask text box issue

There is a problem in VBA text box while filling input mask property:
I am trying to make the combination of date and time:
Hence i put it like below:
00/00/00;0;_00:00;0;_
But while running the application, i am only getting 00/00/00 (Date).
But i remember, i got the result as like 00/00/00 00.00 as expected when i first put the expression as like above;
but now i am not getting it :-(
The InputMask property can contain up to three sections separated by semicolons (;)
Your mask should be like this:
"00/00/00 00:00;0;0"
or
"00/00/00 00:00;0;_" // to display it like __/__/__ __:__
Why not just use the built in "General Date" format? I've found over the years that input masks are very restricting and basically a pain. Although it's been so long since I've used them that I don't recall the details of why I despise them.
This also has the benefit of respecting the users choices of regional date format. For example I always use yyyy-mm-dd format.
Also a client had a situation where the date format was decreed to be Medium Date on all fields. Which is dd-mmm-yy. It later turned out that in a table of 100K records there were twelve dates before 1900. They had simple had something extra keyed in in the year so Windows/Access interpreted those dates as being in the 3rd or 5th century or whatever. Now these dates weren't used in any kind of calculation so it wasn't a big deal. SQL Server upsizing to small date/time fields didn't appreciate those though.