How to Get Year/Month/Date of a DateTime Column by Column.Expressi

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I mean to create a new column with Integer type, which is defined by its
expression to be Year/Month/Date of a DateTime Column.

Of course, It is simple to define such a new column by
Substring(Convert(DateTimeColumn,"System.String"),x,y) to get
Year/Month/Date of DateTime Column if we know the DataTable.Local when we
code the expression.

If not, how to do?

Any suggestions are welcome.

LI Ying
 
Why dont you do the following.

1. Have a column of type datetime or smalldatetime in your database.
2. Adjust your Regional Settings to match your date requirements (YY/MM/DD)
in Windows Control Panel
3. When you read, do the following

MyTextBox.Text = CDate(row("MyDateTimeRow")).ToShortDateString

If your need to manipulate individual elements, you can use, for example:

...... = CDate(row("MyDateTimeRow")).Year ' or Month or Day, etc ...

If your column supports null values, check before the convertion:

..... = CStr(iif(isDBNull(row("MyDateTimeRow")), "Empty Date",
row("MyDateTimeRow").toShortDateString))
 
Thank you for your hint.

I hope to solve this problem in ADO.net instead of in my presentation layer.

If this problem is difficult, is it possible to Get Year/Month/Date of a
DateTime Column by Column.Expression when we know the DataTable's Locale
(Culture)?

For there are so many kinds of Cultures, it is still a difficult task.
 
Back
Top