473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 9038
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ABC | last post by:
How to convert a date string to datetime value with custom date format? e.g. Date String Date Format Result (DateTime value) "05/07/2004" "MM/dd/yyyy" May 7, 2004 "01062005" ...
12
by: DC Gringo | last post by:
How can I convert this pubLatest to a date with format "m/d/yyyy"? Dim pubLatest As New Date pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value -- _____ DC G
19
by: simon | last post by:
I get from the dateTimePicker the value: string="12/18/2003 11:52:28 AM" Now I need to convert this to dateTime. Any function I use: Convert.ToDateTime(string) or Cdate(string), I get an error...
6
by: John A Grandy | last post by:
how are people dealing with the situation where a function accepts a String representation of a date ... but a control on the page or form returns a Date value ... strangely, these Date values...
1
by: abcabcabc | last post by:
I write an application which can let user define own date format to input, How to convert the date string to date value with end-user defined date format? Example, User Defined Date Format as...
5
by: Ray | last post by:
I have a table with some audit date and time columns. Problem is the developer who stored the data left them as DECIMAL type instead of DATE and TIME. Is there a way I can convert the DECIMAL type...
10
by: bonnie.tangyn | last post by:
Dear all In my ASP page, user can enter date in dd/mm/yyyy format. How can I use Javascript to convert dd/mm/yyyy to yyyy-mm-dd hh:mm:ss. Please give me some advices. Cheers Bon
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
6
by: vunet.us | last post by:
How can I convert UTC time such as 1173451235415 to a local time I can read? Thank you
4
by: Ashraf Ansari | last post by:
Hi, How Can I convert MM/dd/yyyy format into dd/MM/yyyy and the date which is converted into dd/MM/yyyy should be in DateTime format. I do not want to store it as a string. Please help ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.