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

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
 
J

John Smith

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))
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top