Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm new to VB.net and this forum. I'm porting the VB application to be compatible with windows 10. The datatable result is displaying the dates incorrectly the dates are displayed in the format of '01\dd\yyyy' the month is coming properly whereas the date and year are improper.

The same code is working properly in case of Windows 7 and it is not working for windows 10. Please let me know if any input is required from my end.

Public Function GetIntegrationLogs( _
                   ByVal FileType As String, _
                   ByVal dtFrom As Date, _
                  ByVal dtTo As Date) As DataTable

        Try
#If ORACLE Then
            Dim dtSC As New DataTable
            Dim adaptSC As New OracleDataAdapter

            'Dim myCommand As New OracleCommand("GetIntegrationLogs", deCCAS.Connection)
            'myCommand.CommandType = CommandType.StoredProcedure
            'myCommand.Parameters.Add("v_FileType", FileType)
            'myCommand.Parameters.Add("v_StartDate", dtFrom)
            'myCommand.Parameters.Add("v_EndDate", dtTo)

            'reader = 

            Dim objCommand As New OracleCommand("GetIntegrationLogs", deCCAS.Connection)
            adaptSC.SelectCommand = objCommand
            Dim sysRefCursor As New OracleParameter
            With sysRefCursor
                .OracleDbType = OracleDbType.RefCursor
                .Direction = ParameterDirection.Output
            End With
            With objCommand
                .CommandType = CommandType.StoredProcedure
                .Parameters.Add("v_FileType", FileType)
                .Parameters.Add("v_StartDate", dtFrom)
                .Parameters.Add("v_EndDate", dtTo)
                .Parameters.Add(sysRefCursor)
            End With

            Dim da As OracleDataAdapter = New OracleDataAdapter(objCommand)
            adaptSC.Fill(dtSC)


What I have tried:

I have tried changing the datatable to dataset but no luck.
Posted
Updated 1-Feb-19 21:42pm
v2

1 solution

If the value is always coming back in a specific format, and that isn't the default DateTime format for the machine, then the Stored Procedure is returning a string based Date value, which is:
1) Stupid. Never convert to strings until the last moment - that's the only time you get access to the users actual Culture and the format he prefers.
2) Out of our control.

So you have two options:
1) Fix the SP to return either a different format (bad) or an actual DateTime value (good).
2) Use DateTime.TryParseExact to convert the values returned by the SP to a DateTime, and then display them - preferably in the users prefered Culture format.
 
Share this answer
 
Comments
Member 14137756 2-Feb-19 5:45am    
Thanks for the reply. I have not converted any strings the result that I'm getting from the stored procedure via VB is in 01\DD\YYYY format. I'm getting the incorrect date format in the entire application. I'm not familiar with VB.net or .net frameworks. I'm trying to change the compatibility of the application from windows 7 to windows 10 the application is giving correct results when I run it in windows 7 but the dates are incorrect in Win 10.

Hints will be appreciated. I did not understand the 1st point where you are suggesting to change SP could you please elaborate the same.

Thanks in Advance
OriginalGriff 2-Feb-19 6:33am    
DateTime values do not have a format - they only get that when they are converted to strings for display, at which point they either user the default format for the machine, or a specific format which is provided when ToString or string.Format is called. If dates are being returned from SQL in a specific format, they are already strings and that means that either the SP is converting them, or the DB design holds them in a VARCHAR or NVARCHAR column.

If your whole app is getting the "wrong format" it's because you are formatting them (explicitly or implicitly) using the default Date format set on the machine and it isn't the one you wanted. Check in the "Time & Language" section of the Settings app, and scroll down to "Formats".
Member 14137756 2-Feb-19 8:42am    
Thanks a lot, Griff :) It worked :) I've been working on it from the last week and it is finally done
OriginalGriff 2-Feb-19 8:53am    
You're welcome!
Member 14137756 2-Feb-19 8:43am    
By Default windows 10 format will be M/DD/YY i changed it to MM/DD/YYYY and it worked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900