Telerik RadGrid Date column is not formatted to the right format - formatting

I have the following column in the Telerik Grid:
<Columns>
<telerik:GridDateTimeColumn DataField="Boardingdate" DataType="System.DateTime" DataFormatString="{0:MM/dd/yyyy}" SortExpression="Boardingdate" UniqueName="Boardingdate"
HeaderStyle-Width="10%"/>
</Columns>
In my sql logic I get this column' date the following way:
cast(convert(varchar(30),meredsopen,101) as date)
And in the sql it's displayed as follows: 2010-10-04
However, when the Grid renders on the page the date's columns have the values like that:
8/23/2018 12:00:00 AM and I cannot sort it as well.
I can convert the date value to string to show 8/23/2018', but in that case, I think, the sorting will be performed on the string and not on the date` value
How can I fix that?

Related

Setting Date Format for multiple date columns in SSRS

I have over 65 columns among which there are about 30 Date Columnns. I want to set it to MM/DD/YYYY. Presently it is also showing the time YYYY-MM-DD hh:mm:ss. I tried correcting this within the SQL query by using cast. The SQL output shows only date, but it again gets represented in DateTime in SSRS. I dont want to right click on 30 columns manually to set date format. Is there a way to set default date format for all date columns in the report?
"Cast" is not helping here since it is about types, not format.
Try using the "convert" function instead.
In your case, it would be
-- use your field name instead of sysdatetime()
select convert(varchar, sysdatetime(), 101/*mm/dd/yyyy format Id*/);
You should be able to select all the fields in the tablix and change the formatting together. You may wish to consider using a parameter for the formatting.

convert TEXT dd/mm/yyyy in SQL column to DATE YYYY-MM-DD

I would love to know the best way to handle data that has been inputted incorrectly as dd/mm/yyyy into a sql database as TEXT and to have it converted into a new column of the table with the datatype as DATE so it is actually stored as yyyy-mm-dd.
Existing text date column name is called "olddate" with an empty column created called "truedate" to house the new data. Each row has the date field, but none are able to be sorted correctly because of this issue.
Any ideas how I can slice and dice the current date into a new DATE field friendly version?
Thanks in advance :-)
That is style 103. So use:
select convert(date, col, 103)
Are you using Oracle? If so, TO_DATE is what you want. You can take in a string that represents a date and convert it to a date using the format you pass it.

How to sort data in asp.net according to varchar datetime field in SQL?

I have a table with a column DateTime with datatype VARCHAR(500).
I'm storing date and time info in it. I'm getting the datetime value using C#
DateTime.Now.ToLongDateString() + "," + DateTime.Now.ToLongTimeString()
This gives me the format like this: 14 July 2015,12:56:04.
I want to sort data in gridview by this column, but since it is of VARCHAR this gives incorrect result. I have understood that there is something about conversion, but haven't been able to do that.
Any suggestion regarding dis will be appreciated.
If you are using boundfield for the datetime column in the Gridview then this will help you in the design of your Gridview:
<asp:boundfield datafield="DateColumn" dataformatstring="{0:MMMM d, yyyy}" htmlencode="false" />

JPA/Hibernate, Query timestamp column ignores time part of criteria

I'm using JPA/Hibernate combination to store entities to an oracle database.
The table contains a TIMESTAMP(6) column to store a date value with time and milliseconds.
Storing and loading the entity works as intended. The "time" part of the java.util.Date field in the entity is processed correctly.
But when I query the table with a native query and where time < :startTime condition the startTime only contains date '30-Jul-14'. The "time" part is truncated.
Hibernates query look like:
select documentta0_.id as id1_14_, documentta0_.id_document as id5_14_, documentta0_.host as host2_14_, documentta0_.task as task3_14_, documentta0_.time as time4_14_
from document_task documentta0_
where documentta0_.task='preview'
and documentta0_.host='my.host.uk'
and documentta0_.time>'30-Jul-14'
order by documentta0_.time ASC
The orm.xml File contains the following column definition:
<basic name="time" optional="false">
<column name="time"/>
<temporal>TIMESTAMP</temporal>
</basic>
How to query with date and time?
Maybe it is just a matter of formatting. In case that you are using something like p6spy, try uncommenting and setting the property to
databaseDialectDateFormat=dd-MM-yy HH:mm:ss.SSSSSS

remove time from sql

Please can any ove suggest me how i can remove time part from sql dates. I have already read 100s of articles and most of them remove the time but leaves 00:00:00 behine which i don't want also i know that i can remove these ZERO's by doing a convert to varchar but unfortunately i cannot change the type of the date column it has to be date type instead of string
Please advise
Thanks
A datetime column in the database will always contain both a date portion and a time portion. SQL Server 2008 introduces types that store only date or only time. But, so long as the column is of type datetime, you'll have to accept that the time portion exists, and you can just ignore it in your application (by applying suitable formatting).
You can add a check constraint to the table to ensure that all entries in the column always have the same time portion (e.g. 00:00:00).
You need to apply a format string to your gridview column to only display the date part. An example of such a string would be dd MMMM yyyy
Is this an ASP.NET gridview? If so there is example code here.
A SQL server DateTime type is a date and a time in SQL 2005 there is no date only field type, you cannot remove the time component and still have a field that is a DateTime type. Your options are the ones you have outlined: Convert to (n)varchar and remove the time componenet, leave it as a DateTime and accept that it has a time component. Why do you wish to remove the time component, what problem would this solve for you.
Further to your comment below, the database is not where you should be formating you Date strings to display in your GridView. You do display layer things in the display layer, in this case in the gridview. You need to use a format string in your data when data binding to the gridview. Yee examples below.
BoundField:
<columns>
<asp:BoundField headertext="CreationDate" dataformatstring="{0:dd-MM-yyyy}" //rearrange these letters as necessary
datafield="CreationDate" />
</columns>
TemplateField
<itemtemplate>
<asp:Label id="Label1" runat="server" Text='<%# Bind("CreationDate", "{0:M-dd-yyyy}") %>'>
</asp:Label>
</itemtemplate>
Try this
select cast(convert(char(11), getdate(), 113) as datetime)
SELECT convert(varchar, getdate(), 101)
OR
Declare #datetime datetime
set #datetime = getdate()
SELECT convert(varchar, #datetime, 101)
DateTime Formats
EDIT:
SQL server 2008 has this
functionality, if you can upgrade.
Just make sure to save 00:00:00 in
your table and remove time part in
Return datetime and format it in your
grid or in your code.
If you could upgrade to SQL2008, that has a separate time command.
I see you say you want to keep it as a datetime object, so as far as I can see if you can't upgrade to 2008 then you are stuck with the zeros
You can't remove time part from thr datetime datatype field.
Only thing you can do is to cast it to the date or varchar datatype before output or to set time part to 00:00:00 before insert/update.
Example:
the statement:
select cast(getdate() as date)
returns only date
What are you trying to do?
Why do you care if the database is saving the exact time or 00:00:00?
When you query this field(inside or outside the DB) you can ignore the time value and show only the date...
Again, say what you are trying to do... I believe it will be easier to help you.
Update mytable set mydatetime=convert(datetime,convert(char(10),mydatetime,103),103)
This will update your table. Hope that is what your looking for.
103: Format datetime as dd/mm/yyyy.