Connecting Tech Pros Worldwide Forums | Help | Site Map

Returning a short date in a datareader

axapta
Guest
 
Posts: n/a
#1: Jun 27 '08
Hi,
I have the following however the date is returned in the long format. I want
to display as dd/mm/yyyy.

If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
End If
Regards


cfps.Christian
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Returning a short date in a datareader


On Jun 16, 9:58 am, "axapta" <jas.jac...@gmail.comwrote:
Quote:
Hi,
I have the following however the date is returned in the long format. I want
to display as dd/mm/yyyy.
>
If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
End If
Regards
if not drReader("offerstatusdate") is dbnull.value then
dim dtTempDate as datetime =
Convert.toDateTime(drReader("offerstatusdate")
txtOfferStatusdate.Text = dtTempdate.ToShortdateTimeString()
end if
Jack Jackson
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Returning a short date in a datareader


On Mon, 16 Jun 2008 08:31:00 -0700 (PDT), "cfps.Christian"
<ge0193387@otc.eduwrote:
Quote:
>On Jun 16, 9:58 am, "axapta" <jas.jac...@gmail.comwrote:
Quote:
>Hi,
>I have the following however the date is returned in the long format. I want
>to display as dd/mm/yyyy.
>>
> If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
> txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
> End If
>Regards
>
>if not drReader("offerstatusdate") is dbnull.value then
dim dtTempDate as datetime =
>Convert.toDateTime(drReader("offerstatusdate")
txtOfferStatusdate.Text = dtTempdate.ToShortdateTimeString()
>end if
Jack Jackson
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Returning a short date in a datareader


On Mon, 16 Jun 2008 08:31:00 -0700 (PDT), "cfps.Christian"
<ge0193387@otc.eduwrote:
Quote:
>On Jun 16, 9:58 am, "axapta" <jas.jac...@gmail.comwrote:
Quote:
>Hi,
>I have the following however the date is returned in the long format. I want
>to display as dd/mm/yyyy.
>>
> If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
> txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
> End If
>Regards
>
>if not drReader("offerstatusdate") is dbnull.value then
dim dtTempDate as datetime =
>Convert.toDateTime(drReader("offerstatusdate")
txtOfferStatusdate.Text = dtTempdate.ToShortdateTimeString()
>end if
You could also use:

txtOfferStatusdate.Text =
Convert.ToDateTime(drReader("offerstatusdate")).To ShortDateString()

or:

Dim offerStatusDateIndex As Integer = _
drReader.GetOrdinal("offerstatusdate")

If Not drReader.IsDBNull(offerStatusDateIndex) Then
txtOfferStatusdate.Text = _
drReader.GetDateTime(offerStatusDateIndex).ToShort DateString()
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#5: Jun 27 '08

re: Returning a short date in a datareader


axapta wrote:
Quote:
Hi,
I have the following however the date is returned in the long format.
That's most likely not a completely accurate description of what's
happening.

If the field is a datetime field in the database, it's not returned as a
formatted string, it's returned as a DateTime value. That means that the
actual formatting is done when you assign the value to the text property.
Quote:
I
want to display as dd/mm/yyyy.
>
If Not drReader.Item("offerstatusdate") Is DBNull.Value Then
txtOfferStatusDate.Text = drReader.Item("offerstatusdate")
End If
Instead of reading the value as an Object and implicitly converting the
DateTime value into a string, read the value as a DateTime value, and
explicitly format it the way that you want it:

txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offersta tusdate")).ToShortDateString()

or

txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offersta tusdate")).ToString("d")

or

txtOfferStatusDate.Text =
drReader.GetDateTime(drReader.GetOrdinal("offersta tusdate")).ToString("dd/MM/yyyy")

Note:
If you are doing this in a loop, you can call GetOrdinal outside the
loop and store the index of the field in an Integer variable.

--
Göran Andersson
_____
http://www.guffa.com
Cor Ligthert[MVP]
Guest
 
Posts: n/a
#6: Jun 27 '08

re: Returning a short date in a datareader


>
Quote:
If the field is a datetime field in the database, it's not returned as a
formatted string, it's returned as a DateTime value. That means that the
actual formatting is done when you assign the value to the text property.
>
In my idea is that a not completely true, databases where returning kind of
DateTime values long before there was the DotNet DateTime structure.
Therefore the DateTime is represented as a value in an object, but not
direct a DotNet DateTime Value.

I never have investigated what value is returned, but surely not a DotNet
DateTime, which is completely different from the ShortDate and DateTime used
in databases even in its long format, at least before version SQL server
2008.

Cor

=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
 
Posts: n/a
#7: Jun 27 '08

re: Returning a short date in a datareader


Cor Ligthert[MVP] wrote:
Quote:
Quote:
>>
>If the field is a datetime field in the database, it's not returned as
>a formatted string, it's returned as a DateTime value. That means that
>the actual formatting is done when you assign the value to the text
>property.
>>
In my idea is that a not completely true, databases where returning kind
of DateTime values long before there was the DotNet DateTime structure.
Therefore the DateTime is represented as a value in an object, but not
direct a DotNet DateTime Value.
>
I never have investigated what value is returned, but surely not a
DotNet DateTime, which is completely different from the ShortDate and
DateTime used in databases even in its long format, at least before
version SQL server 2008.
>
Cor
>
Nitpicking, aren't we? ;)

It's quite irrelevant what format the database uses to send the data to
the database driver (and it probably varies depending on the database
interface chosen). You can not access the data in that format, you can
only access it as a DateTime value.

--
Göran Andersson
_____
http://www.guffa.com
Cor Ligthert[MVP]
Guest
 
Posts: n/a
#8: Jun 27 '08

re: Returning a short date in a datareader



"Göran Andersson" <guffa@guffa.comschreef in bericht
news:OfwI4hJ0IHA.2384@TK2MSFTNGP04.phx.gbl...
Quote:
Cor Ligthert[MVP] wrote:
Quote:
Quote:
>>>
>>If the field is a datetime field in the database, it's not returned as a
>>formatted string, it's returned as a DateTime value. That means that the
>>actual formatting is done when you assign the value to the text
>>property.
>>>
>In my idea is that a not completely true, databases where returning kind
>of DateTime values long before there was the DotNet DateTime structure.
>Therefore the DateTime is represented as a value in an object, but not
>direct a DotNet DateTime Value.
>>
>I never have investigated what value is returned, but surely not a DotNet
>DateTime, which is completely different from the ShortDate and DateTime
>used in databases even in its long format, at least before version SQL
>server 2008.
>>
>Cor
>>
>
Nitpicking, aren't we? ;)
>
It's quite irrelevant what format the database uses to send the data to
the database driver (and it probably varies depending on the database
interface chosen). You can not access the data in that format, you can
only access it as a DateTime value.
>
Exactly

:-)

Cor

Closed Thread