tags:

views:

32

answers:

4

How do I change the format in which the date is stored in a database from mm/dd/yyyy to dd/mm/yyyy? As the MSHFlexGrid reads data directly from the database, its source, need to store the Date in dd/mm/yyyy format.There is no problem in reading mm/dd/yyyy in textbox as dd/mm/yyyy.Please Help!

+2  A: 

Dates are generally stored in the database in an agnostic form, they are only presented in localised formats. You need to look at the localisation setting for you system/component and/or modify your SELECT query to return the date in the format you require (although I suspect that the Grid will still present it in the US format).

Lazarus
+1. Change the regional settings on the system if you can. Otherwise try changing the SQL query to return a string rather than a native date type. As Lazarus says, the grid may still decide the string is a date and format it accordingly.
MarkJ
Thanks i got the answer.By manually changing the registry key [HKEY_CURRENT_USER\Control Panel\International]"sShortDate"="M/D/yyyy" to"sShortDate"="d/M/yyyy".But how do I do it with Code?
Dario Dias
I'm not sure you should be overriding this in code, it's a local system setting. In the US the format you are seeing would be correct, in Japan they would expect dd.mm.yyyy so it's best to let the local machine decide (and effectively the user) how dates should be represented for them.
Lazarus
A: 

Dates are stored as they are. You can't change that. You CAN, however, create a computed column and display the dates as a varchar by converting your date column to a varchar column in whatever format you need, and display that.

(It will be read-only in your form, though)

Conversion functions here: http://msdn.microsoft.com/en-us/library/aa226054%28SQL.80%29.aspx

Computed column here: http://msdn.microsoft.com/en-us/library/ms191250.aspx

David Stratton
+1  A: 

"the MSHFlexGrid reads data directly from the database"

Surely it must be using something in the middle e.g. DataEnvironment designer, ADODB Recordset, etc?

The 'H' in 'MSHFlexGrid' stands for hierarchical: are you showing hierarchical data e.g. binding a hierarchical ADODB Recordset to the grid's DataSource property?

If you don't need hierarchical data, consider the Microsoft DataGrid (MSDatGrd.ocx). You can bind a non-hierarchical ADODB Recordset to it and exploit its Columns' DataFormat properties, which are of type StdFormat.StdDataFormat i.e. have events for _Format and _UnFormat respectively. I use this to add subsecond precision to DATETIME values, replace NULL with '' etc.

UPDATE:

You may be able to create a data sink using the BindingCollection object (requires a reference to Microsoft Data Binding Collection VB 6.0) because a Binding object supports the DataFormat property. For a working example, see Data Sources, Data Sinks.

http://www.aivosto.com/visdev/data.html

onedaywhen
Yes I am.I use Set MSHFG1.DataSource = adodc1.Recordset. MSHFlexGrid MSHFG1 is the name of the control
Dario Dias
I use the MSHFlexGrid because it is read only.I just want it to display the feilds.
Dario Dias
A: 

I don't think changing the system date format is a complete solution because you can change computers and still have the same problem,the best and simplest way is by specifying the format you want in the query, i don't know what database you are using but i would have given you an example.

If the grid is reading directly from the table then you need to create a view querying from that table then specify the format there.

indago