如何将日期转换为字符串值? [英] How to convert date to string value?
问题描述
嗨专家,
我有一个数据字段(birthdate)包含一个datetime数据类型
(mm / dd / yyyy),我该如何转换到mmdd ??
说,生日是8/1/1979并转换为mmdd
DOB = DS.Tables(" AcctInfoTble")。行(3)(BRTHDATE)
strResult.Insert(12,DOB.PadLeft(37,""))
- -------------------------------------------------- -----------------------------------------------
公共函数GenerateA(ByRef strEmpID As String)
Dim strResult As New System.Text.StringBuilder
Dim GPConnection As SqlConnection
Dim dr As SqlDataReader
将GPDataset作为新数据集调暗
GPConnection =新
SqlConnection("。 .................................. ..........")
Dim GPDataAdapter As New SqlDataAdapter(" SELECT
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102,其中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")
尺寸DS作为数据集=新数据集
LName的= DS.Tables(QUOT; AcctInfoTble")行(1).Item(QUOT; LASTNAME" ;)
FName = DS.Tables(" AcctInfoTble")。行(2)(LASTNAME)
DOB = DS.Tables(" AcctInfoTble") ).Rows(3)(BRTHDATE)
....................
''位置13 16N名字
strResult.Insert(12,FName.PadLeft(16," ))
....................
''职位37 4A出生日期
strResult.Insert(12,DOB.PadLeft(37,""))
GPConnection.Dispose()
返回strResult。 ToString
结束功能
* ----------------------- *
发表于:
www.GroupSrv.com
* ----------------------- *
< BLOCKQUOTE>" JenHu" < JE ********** @ Hotmail的双点com.no-spam.invalid> schrieb:
我有一个数据字段(birthdate)包含一个datetime数据类型
(mm / dd / yyyy),怎么能转换成mmdd ??
说,生日是在8/1/1979并转换为mmdd
\\\
Dim s As String = _
Date.ParseExact(_
" 8/1 / 1979",_
" d\ / M\ / yyyy",_
没有_
).ToString(" MMyyyy")
///
- -
Herfried K. Wagner [MVP]
< URL:http://dotnet.mvps.org/>
JenHu
\\\
Dim mystring as string = mydatetimefield.tostring(" MMdd")全部
///
顺便说一下每个日期时间网络中的字段在每种文化格式中都是
MM / dd / yyyy / hh / mm / ss,因此不需要告诉它。
我希望这会有所帮助
Cor
" JenHu" < je ********** @ hotmail-dot-com.no-spam.invalid>
嗨专家,
我有一个数据字段(birthdate)包含一个日期时间数据类型
(mm / dd / yyyy),我怎么能转换为mmdd ??
说,生日是8/1/1979并转换为mmdd
DOB = DS.Tables(" AcctInfoTble")。行(3)(BRTHDATE)
strResult.Insert(12,DOB.PadLeft(37,"") )
----------------------------------------- -------------------------------------------------- --------
公共函数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 ,BRPRDATE来自UPR00102,其中EmployID =''&qu ot; +
strEmpID +"''",GPConnection)
Dim EfundAcct As String
Dim LName as string
Dim FName as string
DOB DOB as string
GPConnection.Open()
GPDataAdapter.Fill(GPDataset," AcctInfoTble")
Dim DS As DataSet = New DataSet
LName = DS .Tables(QUOT; AcctInfoTble")。行(1).Item(QUOT; LASTNAME")
FName参数= DS.Tables(QUOT; AcctInfoTble")。行(2)(" LASTNAME")
DOB = DS.Tables(AcctInfoTble)。行(3)(BRTHDATE)
...................
''位置13 16N名字
strResult.Insert(12,FName.PadLeft(16," ))
...................
''位置37 4A出生日期
strResult.Insert(12,DOB.PadLeft (37,""))
GPConnection.Dispose()
返回strResult.ToString
结束功能
* ----- ------------------ *
发表于:
www.GroupSrv.com
* ----------------------- *
" Cor Ligthert" <无************ @ planet.nl> schrieb:顺便说一句,每个日期时间 Net中的字段在每种文化中的格式为
MM / dd / yyyy / hh / mm / ss,因此不需要告诉它。
''DateTime''不是以字符串格式存储的,并且没有格式本身。
-
Herfried K. Wagner [MVP]
< URL:http://dotnet.mvps.org/>
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
*-----------------------*
"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/>
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
*-----------------------*
"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/>
这篇关于如何将日期转换为字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!