How to convert user-defined custom format date string to date value

A

abcabcabc

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"

input as "2004,03,30" convert to date value as, 30 Mar 2004

Example, User Defined Date Format as "MM dd yyyy"

input as "05 07 2005" convert to date value as, 07 May 2005

Assumption: I cannot change regional language settings, because some PCs may
also use by several users whom have use own faviour date format.
 
D

Dragon

Hi,

This should work:

~
DateTime.ParseExact(InputString, UserDefinedFormat,
Globalization.DateTimeFormatInfo.InvariantInfo)
~

HTH

Roman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top