|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
convert date and time formatsIt used to work in vb6. I don't know the syntax in vb.net
current date and time.... format (cstr(date),"DDMMYY") format(cstr(time),"HHMM") thanks "romy" <royal***@Powerup1.com> wrote in message Dim date As DateTime = DateTime.Parse("August 10, 1980 10:10:23 AM")news:%23gi8U6yeFHA.220@TK2MSFTNGP12.phx.gbl... > It used to work in vb6. I don't know the syntax in vb.net > > current date and time.... > > format (cstr(date),"DDMMYY") > > format(cstr(time),"HHMM") > > thanks > date.ToString("ddMMyy") date.ToString("hhmm") HTH, Mythran "romy" <royal***@Powerup1.com> wrote in message news:%23gi8U6yeFHA.220@TK2MSFTNGP12.phx.gbl... Dim sDate As String = Format(DateTime.Now, "ddMMyy") OR> It used to work in vb6. I don't know the syntax in vb.net > > current date and time.... > > format (cstr(date),"DDMMYY") > > format(cstr(time),"HHMM") > > thanks > > Dim sDate As String = Format(DateTime.Today, "ddMMyy") Dim sTime As String = Format(DateTime.Now, "hhmm") -- Al Reid "romy" <royal***@Powerup1.com> schrieb Now.ToString("ddMMyy")> It used to work in vb6. I don't know the syntax in vb.net > > current date and time.... > > format (cstr(date),"DDMMYY") > format(cstr(time),"HHMM") Now.ToString("HHmm")Have a look at the Date date type and it's members, including shared members. The type Date is exactly the same as the type System.DateTime. - Current date and time: Date.Now (equal to Microsoft.VisualBasic.DateAndTime.Now) - Current date: Date.Today (equal to Microsoft.VisualBasic.DateAndTime.Today) - Current time: Date.TimeOfDay (same time as Microsoft.VisualBasic.DateAndTime.TimeOfDay, but different data type) Armin "romy" <royal***@Powerup1.com> schrieb: 'Dim s As String = date.ToString(<format>)'. For a list of possible formats > It used to work in vb6. I don't know the syntax in vb.net > > current date and time.... > > format (cstr(date),"DDMMYY") > > format(cstr(time),"HHMM") take a look at this article: ..NET Framework Developer's Guide -- Date and Time Format Strings <URL:http://msdn.microsoft.com/library/en-us/cpguide/html/cpconDateTimeFormatStrings.asp> -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Romy,
Be aware that the article that Herfried is showing is (although a very good article) based on the general system.net posibilities. Visual Basic has strong methods for date and time extra above that. As Armin told already. In my opinion is there no reason why VBNet programmers would not use the full strenght of Visual.Basic net instead of that only the subset now showed by Herfried in these pages. Just my thought, Cor "Cor Ligthert" <notmyfirstn***@planet.nl> schrieb: Wake up, Cor. We are talking about converting a date to a string only. > Be aware that the article that Herfried is showing is (although a very > good article) based on the general system.net posibilities. Visual Basic > has strong methods for date and time extra above that. As Armin told > already. VB.NET's methods for doing that are not stronger than those provided by the ..NET Framework. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Herfried,
> Wake up, Cor. We are talking about converting a date to a string only. I wrote this expressely because you are writting this forever in this way > VB.NET's methods for doing that are not stronger than those provided by > the .NET Framework. about other functions as Mid, Len, and whatever. However when the "parse" comes than you have another opinion. The CDate is not a *strong* command, however just like the ones you are forever mentioning in other situations, (which I don't like because of the First as indexer), do I find this one extremly handy. I have nothing to remember beside four characters "CDate" and than it does everything accoording the language/culture settings of a computer. You write forever "why not use VB methods when there are VB methods". I never understand why in this case a "system" method should be used as you always tell. :-) CorCor,
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb: I use VB.NET's own functions whenever possible.>> Wake up, Cor. We are talking about converting a date to a string only. >> VB.NET's methods for doing that are not stronger than those provided by >> the .NET Framework. > > I wrote this expressely because you are writting this forever in this way > about other functions as Mid, Len, and whatever. > However when the "parse" comes than you have another opinion. I hardly ever parse a date without specifying a certain date format. Typically in Windows Forms applications processing user input I prefer a DateTimePicker control for choosing dates over a textbox and string parsing. When reading dates from a file, I use 'DateTime.ParseExact' to make sure the data is read the way I want it to be read on every system. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb Of course! DateTimePicker! That's the solution! :-))> I hardly ever parse a date without specifying a certain date format. > Typically in Windows Forms applications processing user input I > prefer a DateTimePicker control for choosing dates over a textbox > and string parsing. When reading dates from a file, I use > 'DateTime.ParseExact' to make sure the data is read the way I want > it to be read on every system. Armin |
|||||||||||||||||||||||