Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Bug Reports (Closed)
 V33(.03) BUG+FIX: StrToDate
 Forum Locked  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 3

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 02 May 2002 :  17:37:19  Show Profile  Send ruirib a Yahoo! Message
Guys,

After some thinking on whether I should raise this as a bug, I decided that I should. The StrToDate function currently in inc_functions.asp fails in (at least some) computers with non US date formats. Just today I helped two people with problems due to the bad behavior of the function. I also had a previous bout with an Events MOD that failed miserably because of the same problem.

Will this be addressed in 3.4? Anyhow, for people with 3.3.03 and non US date formats, here goes my proposal (as copied from an earlier post from the Dev discussions forums):


function StrToDate(strDateTime)

	if ChkDateFormat(strDateTime) then 
		'Testing for server format

		If strComp(Month("04/05/2002"),"4")=0 Then
			StrToDate = cdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
		Else
			 StrToDate = cdate("" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
		End If

	else
		tmpDate = DatePart("m",strForumTimeAdjust) & "/" & DatePart("d",strForumTimeAdjust) & "/" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)
		StrToDate = "" & tmpDate
	end if
end function


This doesn't change a thing for the people currently using US dates format. It helps those who have UK formats.
It has the additional advantage of avoiding the need to add two fixes to the the current code (ReadLastHereDate in inc_functions.asp and another small change at forum.asp). These two fixes only address symptoms, not the cause.



-------------------------------------------------
Installation Guide | Do's and Dont's | MODs


Edited by - ruirib on 02 May 2002 17:38:29

Edited by - Davio on 07 March 2003 11:33:27

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 02 May 2002 :  18:35:00  Show Profile
Instead of using the cdate function, how about using something like:

StrToDate = DateSerial(CInt(Mid(strDateTime, 1, 4)), CInt(Mid(strDateTime, 5, 2)), CInt(Mid(strDateTime, 7, 2)))
+ TimeSerial(CInt(Mid(strDateTime, 9, 2)), CInt(Mid(strDateTime, 11, 2)), CInt(Mid(strDateTime, 13, 2)))


Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 02 May 2002 :  19:06:46  Show Profile  Send ruirib a Yahoo! Message
The advantage being?

-------------------------------------------------
Installation Guide | Do's and Dont's | MODs
Go to Top of Page

pweighill
Junior Member

United Kingdom
453 Posts

Posted - 03 May 2002 :  15:08:26  Show Profile
The advantage being that DateSerial and TimeSerial work no matter what the date & time formats the server are set to, whereas cdate doesn't.

Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 03 May 2002 :  16:40:43  Show Profile  Send ruirib a Yahoo! Message
Well, the purpose of my function is to determine the date format in use. So it seems to me that in that specific situation using DateSerial or cdate doesn't make any difference, since I admit that I determined the format in use with the month comparison...


And to tell you the truth I just changed the already existing function from Snitz, to make it work where it failed. So far I have no knowledge of situations with Snitz users where cdate has failed, but I have nothing against using DateSerial, if your prefer it.


-------------------------------------------------
Installation Guide | Do's and Dont's | MODs



Edited by - ruirib on 03 May 2002 16:56:50
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 03 May 2002 :  18:51:08  Show Profile  Visit HuwR's Homepage
I don't see how your dateserial would help, if you recheck what ruirib posted, you will notice that he parses the strToDate in two different orders to get the correct one, and it is this part which is important since the month and date get swapped when writing the strToDate which is passed to it.

Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 03 May 2002 :  19:46:32  Show Profile
fixed in v3.4
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 07 May 2002 :  12:29:36  Show Profile  Send ruirib a Yahoo! Message
Well, yes this needs a new fix. Sorry guys, my own stupidity stopped me from seeing it .

The version posted above still has a problem, when the ChkDateFormat fails. That failure may occur, for example, when the function is called from forum.asp, with strForumTimeAdjust as a parameter. To fix it, the part relative to the situation where ChkDateFormat fails needs to be treated in a similar way to the part where it does not fail, that is, by considering the server date format. So here it is, hopefully, this function final version, with the latest changes in red:


function StrToDate(strDateTime)

if ChkDateFormat(strDateTime) then
'Testing for server format
If strComp(Month("04/05/2002"),"4")=0 Then
StrToDate = cdate("" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
Else
StrToDate = cdate("" & Mid(strDateTime, 7,2) & "/" & Mid(strDateTime, 5,2) & "/" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
End If

else
If strComp(Month("04/05/2002"),"4")=0 Then
tmpDate = DatePart("m",strForumTimeAdjust) & "/" & DatePart("d",strForumTimeAdjust) & "/" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)
Else
tmpDate = DatePart("d",strForumTimeAdjust) & "/" & DatePart("m",strForumTimeAdjust) & "/" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)
End If


StrToDate = tmpDate
end if
end function




-------------------------------------------------
Installation Guide | Do's and Dont's | MODs


Edited by - ruirib on 07 May 2002 12:30:32
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 11 August 2002 :  08:57:02  Show Profile
I think this is more compact and will work in all locales.



function StrToDate(strDateTime)
if ChkDateFormat(strDateTime) then
StrToDate = cdate("" & Mid(strDateTime, 7,2) & "-" & Monthname(Mid(strDateTime, 5,2)) & "-" & Mid(strDateTime, 1,4) & " " & Mid(strDateTime, 9,2) & ":" & Mid(strDateTime, 11,2) & ":" & Mid(strDateTime, 13,2) & "")
else
tmpDate = DatePart("d",strForumTimeAdjust) & "-" & Monthname(DatePart("m",strForumTimeAdjust)) & "-" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)
StrToDate = cDate(tmpDate)
end if
end function



CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain

It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.

Prayer Of Forgiveness
"I forgive all living beings. May all living beings forgive me!
I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated)

Edited by - GauravBhabu on 11 August 2002 10:05:26
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 11 August 2002 :  10:07:35  Show Profile  Visit HuwR's Homepage
? your function is pretty much what it was originally, which is what causes the problems.

The problem is that dates that get swapped are VALID dates, which is why ruirib's function checks an actual date to ascertain what the server is doing
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 11 August 2002 :  10:22:39  Show Profile
quote:
Originally posted by HuwR

? your function is pretty much what it was originally, which is what causes the problems.



Only difference in the function posted by me is that it passes the Monthname to cdate function instead of month number.

quote:

The problem is that dates that get swapped are VALID dates, which is why ruirib's function checks an actual date to ascertain what the server is doing


Month and day swapping occurs because the Cdate function processes the dates differently under different locale settings.

cdate function will return
8/11/2002(mm/dd/yyyy) as
8/11/2002(mm/dd/yyyy) or
8/11/2002(dd/mm/yyyy)
depending on the locale settings.

But it will always return 11-Aug-2002 as
8/11/2002(mm/dd/yyyy) or
11/8/2002(dd/mm/yyyy).

The function is more compact and there is no need to find the server settings.

CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain

It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.

Prayer Of Forgiveness
"I forgive all living beings. May all living beings forgive me!
I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated)
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 11 August 2002 :  13:52:33  Show Profile  Send ruirib a Yahoo! Message
quote:
Originally posted by GauravBhabu


Only difference in the function posted by me is that it passes the Monthname to cdate function instead of month number.


Well that makes the difference between this strategy succeeding or failing.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 11 August 2002 :  16:49:06  Show Profile  Visit HuwR's Homepage
GauravBhabu,
I beg to differ.

if you pass it

8/11/2002(mm/dd/yyyy) or
11/8/2002(dd/mm/yyyy).

you will get a different result for monthname depending on the server because datepart 'm' will not be the same, hence the reason ruirib compares an actual date to see whether the function returns it as the correct month or not
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 11 August 2002 :  17:07:07  Show Profile  Send ruirib a Yahoo! Message
Well Huw, I think you're right if you think in terms of a generic function, to be applied with other dates than Snitz.
However, with Snitz dates, the month always comes at the 5th and 6th positions of the string and the day at the 7th and 8th. So I believe that Gaurav's function will always returns the same values as my own's, since cdate will always get a date in the format "dd-MonthName-yyyy" and will output it according to the server date settings. My own testing, both with US and UK server settings seems to confirm that.
Remember that StrToDate will always get dates in the Snitz format "YYYYMMDDHHMMSS", so the type of confusion you mentioned won't happen, IMO.

You can keep using "my" version, though. I see no problem with that


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 11 August 2002 17:36:54
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 11 August 2002 :  17:41:29  Show Profile  Visit HuwR's Homepage
quote:

StrToDate will always get dates in the Snitz format "YYYYMMDDHHMMSS"


I wouldn't bet on it. I have seen them saved as YYYYDDMMHHMMSS

and besides, the problem is this line anyway
tmpDate = DatePart("d",strForumTimeAdjust) & "-" & Monthname(DatePart("m",strForumTimeAdjust)) & "-" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)

which uses a date not the forums string format
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 11 August 2002 :  18:06:13  Show Profile  Send ruirib a Yahoo! Message
quote:
Originally posted by HuwR
I wouldn't bet on it. I have seen them saved as YYYYDDMMHHMMSS


Well mine would fail there also.

quote:

and besides, the problem is this line anyway
tmpDate = DatePart("d",strForumTimeAdjust) & "-" & Monthname(DatePart("m",strForumTimeAdjust)) & "-" & DatePart("yyyy",strForumTimeAdjust) & " " & DatePart("h",strForumTimeAdjust) & ":" & DatePart("n",strForumTimeAdjust) & ":" & DatePart("s",strForumTimeAdjust)


I think that is also taken care of because of the line following those,

StrToDate = cDate(tmpDate)


Since both DatePart and cDate use the server date and time settings, I think this time Gaurav's suggestion really works. I also think it's a more elegant solution and I like elegant solutions.

Besides the elegance of the solution, I think the differences between both are minimal. StrToDate doesn't get called that many times to make a significative difference in performance, the extra call to strComp and the additional if "my" function adds.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Next Page
 Forum Locked  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.18 seconds. Powered By: Snitz Forums 2000 Version 3.4.07