473,549 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Acct InfoTble").Rows (3)("BRTHDATE")
strResult.Inser t(12, DOB.PadLeft(37, " "))

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

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

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

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

GPConnection.Op en()
GPDataAdapter.F ill(GPDataset, "AcctInfoTb le")
Dim DS As DataSet = New DataSet
LName = DS.Tables("Acct InfoTble").Rows (1).Item("LASTN AME")
FName = DS.Tables("Acct InfoTble").Rows (2)("LASTNAME")
DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")

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

GPConnection.Di spose()
Return strResult.ToStr ing
End Function

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
15 9051
"JenHu" <je**********@h otmail-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("MMy yyy")
///

--
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**********@h otmail-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("Acct InfoTble").Rows (3)("BRTHDATE")
strResult.Inser t(12, DOB.PadLeft(37, " "))

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

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

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

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

GPConnection.Op en()
GPDataAdapter.F ill(GPDataset, "AcctInfoTb le")
Dim DS As DataSet = New DataSet
LName = DS.Tables("Acct InfoTble").Rows (1).Item("LASTN AME")
FName = DS.Tables("Acct InfoTble").Rows (2)("LASTNAME")
DOB = DS.Tables("Acct InfoTble").Rows (3)("BRTHDATE")

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

GPConnection.Di spose()
Return strResult.ToStr ing
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&conten t-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.ToStr ing' + 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3090
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" "ddMMyyyy" June 1, 2005 "09-07-05" "MM-dd-yy" Sept 7, 2005 Is there any functions to convert?
12
3829
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
8738
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 message: String was not recognized as a valid DateTime. What should I do? Use replace function and mid function on string and at the end convert it...
6
1957
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 can be Nothing but not in the sense of a object reference to Nothing ... rather, you supposedly can use an equality comparison MyControl.Date =...
1
4587
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 "dd/MM/yyyy" input as "01082003" convert to date value as, 01 Aug 2003 Example, User Defined Date Format as "yyyy,dd,MM"
5
43808
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 to DATE or TIME? The column data is in the date form YYYYMMDD (i.e. 20060308 = March 8 2006). I want to get the data into a DATE type. I tried...
10
162636
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
19203
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 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
6
21182
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
30248
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 Thanks in advance
0
7471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7740
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3496
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.