Re: retrieve date from string by Co
Co
Sun Oct 12 16:02:44 CDT 2008
On 12 okt, 22:13, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> I have a feeling your function can be simplified, but that depends on my
> understanding something about how it is used. The one thing I am unclear =
on
> is, for your ConvDate function, what are the possible forms the DateIn
> argument can take? Is it always in the form 20 October 2008 like your
> original post showed? Or could it be differently formatted (if so, how)?
>
> And when you asked "Is the next date: 01-03-2008 -> 1 March 2008 or 3
> January 2008?", how does this relate to what you are doing? I don't see
> where that fits in to your function's use... it that a second question
> regarding how to show a newly calculated date back to the user of your
> program?
>
> --
> Rick (MVP - Excel)
>
> "Co" <vonclausow...@gmail.com> wrote in message
>
> news:7aeb89fb-0f59-4c64-81b4-1eab35a700f6@m36g2000hse.googlegroups.com...
> On 12 okt, 17:26, "Larry Serflaten" <serfla...@usinternet.com> wrote:
>
> > "Co" <vonclausow...@gmail.com> wrote
>
> > Now the only thing I have to find out is how to handle the regional
> > settings of a machine.
> > Is the next date: 01-03-2008 -> 1 March 2008 or 3 January 2008?
>
> > Is there anything to settle that?
> > ---------------
>
> > CDate uses the localility settings of the system. I don't know why
> > you got a type mismatch, it works fine here....
>
> > If your text is going to be in local format you need do nothing, but
> > if not, you're in for a real treat.... ;-)
>
> > (There simply isn't any way to know the format other than taking a
> > sampling of several from the same locale and inferring the order)
>
> > LFS
>
> Would this be a solution? I get the right results when I try several
> date formats:
>
> Public Function ConvDate(DateIn As String) As String
>
> =A0 =A0 Dim stDate As String
> =A0 =A0 Dim dDate As Date
> =A0 =A0 Dim i As Integer
> =A0 =A0 Const sUKMonths =3D
> "JANUARY,FEBRUARY,MARCH,MAY,JUNE,JULY,AUGUST,OCTOBER,MAR,OCT"
> =A0 =A0 Const sNLMonths =3D
> "JANUARI,FEBRUARI,MAART,MEI,JUNI,JULI,AUGUSTUS,OKTOBER,MRT,OKT"
> =A0 =A0 Dim sItem() As String
> =A0 =A0 Dim sReplace() As String
> =A0 =A0 Dim sDayMonthIssue As String
>
> =A0 =A0 DateIn =3D UCase(DateIn)
> =A0 =A0 sDayMonthIssue =3D GetLocaleItem(LOCALE_USER_DEFAULT,
> LOCALE_SLONGDATE)
> =A0 =A0 If Left(sDayMonthIssue, 1) =3D "d" Then
> =A0 =A0 =A0 =A0stDate =3D Format(DateIn, "dd/mm/yyyy hh:mm")
> =A0 =A0 Else
> =A0 =A0 =A0 =A0stDate =3D Format(DateIn, "mm/dd/yyyy hh:mm")
> =A0 =A0 End If
> =A0 =A0 If IsDate(stDate) Then
> =A0 =A0 =A0 =A0 dDate =3D CDate(stDate)
> =A0 =A0 =A0 =A0 ConvDate =3D Format(CStr(dDate), "YYYYMMDD")
> =A0 =A0 Else 'try to solve date problem
>
> =A0 =A0 =A0 =A0 sItem =3D Split(sUKMonths, ",", -1)
> =A0 =A0 =A0 =A0 sReplace =3D Split(sNLMonths, ",", -1)
> =A0 =A0 =A0 =A0 For i =3D 0 To UBound(sItem)
> =A0 =A0 =A0 =A0 =A0 =A0 If InStr(stDate, sItem(i)) Then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0stDate =3D Replace(stDate, sItem(i), sRepl=
ace(i))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0dDate =3D CDate(stDate)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ConvDate =3D Format(CStr(dDate), "YYYYMMDD=
")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Exit For
> =A0 =A0 =A0 =A0 =A0 =A0 End If
> =A0 =A0 =A0 =A0 Next
>
> =A0 =A0 End If
>
> Marco
The DateIn can take a lot of forms. That is my main problem.
It depends of course where the document is coming from.
Unfortunately we didn't manage to create a global way of writing a
date.
Sometimes it starts with the year, sometimes with the month and
sometimes
with the day. The easiest is when the month is like Oct or October.
When everything is in numbers, there's no way to find out what is
what.
08-08-07?