469,942 Members | 2,545 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,942 developers. It's quick & easy.

How to convert date to string value?

Hi expert,

I have a data field (birthdate) contains a datetime datatype
(mm/dd/yyyy), how can I convert to mmdd??
say, the birthday is 8/1/1979 and convert to mmdd

DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")
strResult.Insert(12, DOB.PadLeft(37, " "))

---------------------------------------------------------------------------------------------------

Public Function GenerateA(ByRef strEmpID As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet

GPConnection = New
SqlConnection("................................... ..........")
Dim GPDataAdapter As New SqlDataAdapter("SELECT
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " +
strEmpID + "'", GPConnection)

Dim EfundAcct As String
Dim LName as string
Dim FName as string
Dim DOB as string

GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
LName = DS.Tables("AcctInfoTble").Rows(1).Item("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(2)("LASTNAME")
DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")

....................
'Position 13 16N First Name
strResult.Insert(12, FName.PadLeft(16, " "))
....................
'Position 37 4A Birthdate
strResult.Insert(12, DOB.PadLeft(37, " "))

GPConnection.Dispose()
Return strResult.ToString
End Function

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
15 8777
"JenHu" <je**********@hotmail-dot-com.no-spam.invalid> schrieb:
I have a data field (birthdate) contains a datetime datatype
(mm/dd/yyyy), how can I convert to mmdd??
say, the birthday is 8/1/1979 and convert to mmdd


\\\
Dim s As String = _
Date.ParseExact( _
"8/1/1979", _
"d\/M\/yyyy", _
Nothing _
).ToString("MMyyyy")
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
JenHu

\\\
Dim mystring as string = mydatetimefield.tostring("MMdd") that is all
///

By the way every "datetime" field in Net is in every culture in the format
MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.

I hope this helps

Cor

"JenHu" <je**********@hotmail-dot-com.no-spam.invalid>
Hi expert,

I have a data field (birthdate) contains a datetime datatype
(mm/dd/yyyy), how can I convert to mmdd??
say, the birthday is 8/1/1979 and convert to mmdd

DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")
strResult.Insert(12, DOB.PadLeft(37, " "))

---------------------------------------------------------------------------------------------------

Public Function GenerateA(ByRef strEmpID As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
Dim GPDataset As New DataSet

GPConnection = New
SqlConnection("................................... ..........")
Dim GPDataAdapter As New SqlDataAdapter("SELECT
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " +
strEmpID + "'", GPConnection)

Dim EfundAcct As String
Dim LName as string
Dim FName as string
Dim DOB as string

GPConnection.Open()
GPDataAdapter.Fill(GPDataset, "AcctInfoTble")
Dim DS As DataSet = New DataSet
LName = DS.Tables("AcctInfoTble").Rows(1).Item("LASTNAME")
FName = DS.Tables("AcctInfoTble").Rows(2)("LASTNAME")
DOB = DS.Tables("AcctInfoTble").Rows(3)("BRTHDATE")

...................
'Position 13 16N First Name
strResult.Insert(12, FName.PadLeft(16, " "))
...................
'Position 37 4A Birthdate
strResult.Insert(12, DOB.PadLeft(37, " "))

GPConnection.Dispose()
Return strResult.ToString
End Function

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Nov 21 '05 #3
"Cor Ligthert" <no************@planet.nl> schrieb:
By the way every "datetime" field in Net is in every culture in the format
MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.


'DateTime' is not stored in string format and doesn't have a format per-se.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4

"Herfried K. Wagner [MVP]"
By the way every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.


'DateTime' is not stored in string format and doesn't have a format
per-se.

Did I write that?

What do you want to say with this sentence?

Cor
Nov 21 '05 #5
"Cor Ligthert" <no************@planet.nl> schrieb:
By the way every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.


'DateTime' is not stored in string format and doesn't have a format
per-se.

Did I write that?


You wrote that "every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #6
>>>> By the way every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.

'DateTime' is not stored in string format and doesn't have a format
per-se.

Did I write that?


You wrote that "every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.

Can you give me than what it is?

Cor
Nov 21 '05 #7
"Cor Ligthert" <no************@planet.nl> schrieb:
> By the way every "datetime" field in Net is in every culture in the
> format MM/dd/yyyy/hh/mm/ss, therefore it is not needed to tell that.

'DateTime' is not stored in string format and doesn't have a format
per-se.

Did I write that?


You wrote that "every "datetime" field in Net is in every culture in the
format MM/dd/yyyy/hh/mm/ss", which is either misleading or false.

Can you give me than what it is?


It's formatless. In VB6, dates were stored as a 'Double' value. That's not
the case for .NET. In .NET, 'DateTime' values are stored in a 'Int64'.

<URL:http://sharedsourcecli.sscli.net/source/browse/sharedsourcecli/clr/src/bcl/system/datetime.cs?rev=1.1.1.1&content-type=text/vnd.viewcvs-markup>
says:

| // This value type represents a date and time. Every DateTime
| // object has a private field (Ticks) of type Int64 that stores the
| // date and time as the number of 100 nanosecond intervals since
| // 12:00 AM January 1, year 1 A.D. in the proleptic Gregorian Calendar.

So, on the one hand, there is the internal representation, which doesn't
have a human-readable format. In this particular case the date and time is
stored as "the number of 100 nanosecond intervals since 12:00 AM January 1,
year 1 A.D. in the proleptic Gregorian Calendar". On the other hand, there
is the string representation of a 'DateTime', which depends on the culture.
There is no generic format string that applies to all cultures.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #8
Herfried,
So, on the one hand, there is the internal representation, which doesn't
have a human-readable format. In this particular case the date and time
is stored as "the number of 100 nanosecond intervals since 12:00 AM
January 1, year 1 A.D. in the proleptic Gregorian Calendar". On the other
hand, there is the string representation of a 'DateTime', which depends on
the culture. There is no generic format string that applies to all
cultures.


This is an answer on another question (where did I write that it was in
human readable format by instance) or did tell this in connection with a
string format.

You said that I am misleading when I tell that a datetime is in dotNet
always

Months-Days-Years-Hours-minutes-seconds

So tell than what it is

I am not interested in what kind of bit format it is stored in memory at
all, DateTime is a value format in Net and a format in a database, which I
am thinking from that it is always in the above format. When not, tell than
what format it is and not a kind of novel.

Cor
Nov 21 '05 #9
"Cor Ligthert" <no************@planet.nl> schrieb:
You said that I am misleading when I tell that a datetime is in dotNet
always

Months-Days-Years-Hours-minutes-seconds

So tell than what it is
It's actually a number of 100 nanoseconds.

This value can be /formatted/ in the format you gave using
'DateTime.ToString' + a specific format string or may be formatted this way
in certain cultures, but 'DateTime' in .NET is not always in the format you
gave.
I am not interested in what kind of bit format it is stored in memory at
all, DateTime is a value format in Net and a format in a database, which I
am thinking from that it is always in the above format. When not, tell
than what format it is and not a kind of novel.


I already told you in what format 'DateTime' is stored in .NET.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #10
Herfried,

I asked you what format than is. I told that it was not needed to tell the
"MM-dd-yyyy" format with a "datetime" value. You told that I am *misleading*
people.

I don't know what "irreführend" means in German, however the translation
from "misleading" in Dutch "misleiden" says that there should be a personal
benefit for the one who does that. I cannot see in anyway how I can get a
personal benefit by telling what I did, while it is actual even true.

You are telling something about the way dates and times are written in
different cultures, which has nothing to do with the way datetime values are
stored in dotNet.

Cor
Nov 21 '05 #11
"Cor Ligthert" <no************@planet.nl> schrieb:
I asked you what format than is.
And I answered this question.
I don't know what "irreführend" means in German, however the translation
from "misleading" in Dutch "misleiden" says that there should be a
personal benefit for the one who does that. I cannot see in anyway how I
can get a personal benefit by telling what I did, while it is actual even
true.
That's not true for the German language, and I believe it's not true for
English. Misleading IMO means that something points somebody in the wrong
direction.
You are telling something about the way dates and times are written in
different cultures, which has nothing to do with the way datetime values
are stored in dotNet.


Re-read my post. I was talking about both, the internal representation of
'DateTime' ('Int64') /and/ culture-specific formats (format strings).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #12
Herfried,

Basicly you are right, the datetime is a value what is internaly as well as
in a database a tick that start on a certain date.

However you started telling that it was "no" string what brought me on the
wrong route, because I had not written that either.

I have to admit that I wrote it the last weeks in a wrong way in this
newsgroup telling that it was internally by Microsoft MM-dd-yyyy.

Just to show that I knew it. in past I have sometimes written that it was
crazy that they had choosen in SQL this
Datetime (SQLSever)

Date and time data from January 1, 1753 through December 31, 9999, to an
accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds
or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007
seconds, as shown in the table.

When you read this, than you get the idea that the one who decided this,
believes that humans live started at 1753 and SQL server will exist untill
the year 9999. However we don't know the religion form the one who decided
this.

But I have written in this newsgroups for some week that the internal
format is MM-dd-yyyy. That is not to correct therefore in future I will
write it as DateTime is represented in VSNet as MM-dd-yyyy what is a
translation from a tickcount, which starts on a point depending in the
source that it is used.

So thank you for bringing me on the right track back again, however please
next time more in the way of the message before your last one in this
thread, and instead of intervals "ticks". The word ticks had triggered me
directly what you wanted to say to me.

But it stays of course that for somebody who has a problem with "datetime"
it is not needed to give the format of that, it is everywhere the same.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
"Cor Ligthert" <no************@planet.nl> schrieb:
I asked you what format than is.


And I answered this question.
I don't know what "irreführend" means in German, however the translation
from "misleading" in Dutch "misleiden" says that there should be a
personal benefit for the one who does that. I cannot see in anyway how I
can get a personal benefit by telling what I did, while it is actual even
true.


That's not true for the German language, and I believe it's not true for
English. Misleading IMO means that something points somebody in the wrong
direction.
You are telling something about the way dates and times are written in
different cultures, which has nothing to do with the way datetime values
are stored in dotNet.


Re-read my post. I was talking about both, the internal representation of
'DateTime' ('Int64') /and/ culture-specific formats (format strings).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #13
Herfried,

Basicly you are right, the datetime is a value what is internaly as well as
in a database a tick that start on a certain date.

However you started telling that it was "no" string what brought me on the
wrong route, because I had not written that either.

I have to admit that I wrote it the last weeks in a wrong way in this
newsgroup telling that it was internally by Microsoft MM-dd-yyyy.

Just to show that I knew it. in past I have sometimes written that it was
crazy that they had choosen in SQL this
Datetime (SQLSever)

Date and time data from January 1, 1753 through December 31, 9999, to an
accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds
or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007
seconds, as shown in the table.

When you read this, than you get the idea that the one who decided this,
believes that humans live started at 1753 and SQL server will exist untill
the year 9999. However we don't know the religion form the one who decided
this.

But I have written in this newsgroups for some week that the internal
format is MM-dd-yyyy. That is not to correct therefore in future I will
write it as DateTime is represented in VSNet as MM-dd-yyyy what is a
translation from a tickcount, which starts on a point depending in the
source that it is used.

So thank you for bringing me on the right track back again, however please
next time more in the way of the message before your last one in this
thread, and instead of intervals "ticks". The word ticks had triggered me
directly what you wanted to say to me.

But it stays of course that for somebody who has a problem with "datetime"
it is not needed to give the format of that, it is everywhere the same.

Cor

"Herfried K. Wagner [MVP]" <hi***************@gmx.at>
"Cor Ligthert" <no************@planet.nl> schrieb:
I asked you what format than is.


And I answered this question.
I don't know what "irreführend" means in German, however the translation
from "misleading" in Dutch "misleiden" says that there should be a
personal benefit for the one who does that. I cannot see in anyway how I
can get a personal benefit by telling what I did, while it is actual even
true.


That's not true for the German language, and I believe it's not true for
English. Misleading IMO means that something points somebody in the wrong
direction.
You are telling something about the way dates and times are written in
different cultures, which has nothing to do with the way datetime values
are stored in dotNet.


Re-read my post. I was talking about both, the internal representation of
'DateTime' ('Int64') /and/ culture-specific formats (format strings).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #14
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
So thank you for bringing me on the right track back again, however please
next time more in the way of the message before your last one in this
thread, and instead of intervals "ticks". The word ticks had triggered me
directly what you wanted to say to me.


You are welcome!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #15
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
So thank you for bringing me on the right track back again, however please
next time more in the way of the message before your last one in this
thread, and instead of intervals "ticks". The word ticks had triggered me
directly what you wanted to say to me.


You are welcome!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by DC Gringo | last post: by
19 posts views Thread by simon | last post: by
6 posts views Thread by John A Grandy | last post: by
5 posts views Thread by Ray | last post: by
10 posts views Thread by bonnie.tangyn | last post: by
7 posts views Thread by elliotng.ee | last post: by
6 posts views Thread by vunet.us | last post: by
4 posts views Thread by Ashraf Ansari | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.