Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2012, 02:18 AM
Registered User
 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default MMddyy to yyyymmdd

Hi
is there a way to convert MMddyyyy to yyyymmdd , stored in a text file
using vb.net

Any ideas are welcome
regards
 
Old March 29th, 2012, 03:05 AM
Authorized User
 
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
Default

Hi,


just parse the string to date and use the toString with a specific DateFormat afterwards.

There are actually hundred ways to do this, in one way it could look like this:
Code:
 
         Public Function CustomConversion(dateString as String) As String
         	Dim dateFormatIn, dateFormatOut As String  
         	Dim myDate As Date

         	dateFormatIn = "MMddyyyy"
         	dateFormatOut = "yyyyMMdd" 
         	
         	myDate = Date.ParseExact(dateString, dateFormatIn, provider)
         	return myDate.ToString(dateFormatOut) 
         	
         End Function
You probably want to make it a bit safer by using TryParseExact etcetera but you get the idea..

Success !
 
Old March 29th, 2012, 03:52 AM
Registered User
 
Join Date: Mar 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by disel2010 View Post
Hi,


just parse the string to date and use the toString with a specific DateFormat afterwards.

There are actually hundred ways to do this, in one way it could look like this:
Code:
 
         Public Function CustomConversion(dateString as String) As String
         	Dim dateFormatIn, dateFormatOut As String  
         	Dim myDate As Date

         	dateFormatIn = "MMddyyyy"
         	dateFormatOut = "yyyyMMdd" 
         	
         	myDate = Date.ParseExact(dateString, dateFormatIn, provider)
         	return myDate.ToString(dateFormatOut) 
         	
         End Function
You probably want to make it a bit safer by using TryParseExact etcetera but you get the idea..

Success !
Hi

can you tell me how to open the file here like
Public Function CustomConversion(dateString as String) As String
Dim dateFormatIn, dateFormatOut As String
Dim myDate As Date ' where can i put the code open file C:\dates.txt

dateFormatIn = "MMddyyyy"
dateFormatOut = "yyyyMMdd"

myDate = Date.ParseExact(dateString, dateFormatIn, provider)
return myDate.ToString(dateFormatOut)

End Function





Similar Threads
Thread Thread Starter Forum Replies Last Post
date format yyyymmdd belete ASP.NET 2.0 Basics 5 October 29th, 2007 08:24 AM
Validating date(yyyymmdd) with RegularExpressionVa belete ASP.NET 2.0 Basics 2 October 23rd, 2007 12:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.