Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Strange date formatting problem

Using Excel 2000 to 2003.
I have to compare columns of dates in a VBA array. This array is delared as
follows:
Public TableArray()
The dates are entered via another variant array with a function that goes as
follows:

Function ConvertDates(ByVal intDate As Long) As String

If intDate = 0 Or intDate = Null Then
ConvertDates = ""
Else
ConvertDates = _
Format(DateSerial(Left(intDate, 4), _
Mid(intDate, 5, 2), _
Right(intDate, 2)), "dd/mm/yyyy")
End If

End Function

Now I have to compare dates in 2 colums of the TableArray.
I can't get this to work and I found out that this is because the dates are
stored in the array in the
"mm/dd/yyyy" format. Strangely when you assign the array to the sheet it
appears fine as "dd/mm/yyyy".
Now I have tried all kind of ways to compare the dates in the 2 columns, but
nil works. This is because I have to
do the date comparisons in proper time units like a real calendar month,
rather than 30 days.
This goes via another function like this:

(snippet)
AlterDate = DateSerial(Year(oldDate), _
Month(oldDate) - lCount, _
Day(oldDate))

The month and day being the other way round messes this function up.

Would there be any solution to this rather than swapping the day and month
via a temp variable?

Thanks for any advice.



RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Strange date formatting problem

Your problem most likely comes from the fact that this code will only
work if intDate has the correct number of digits. Something as simple
as Jan – Sept being given as “1” – “9” instead of “01” – “09” could
cause it to malfunction. - Pikus


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Strange date formatting problem

That is not the problem.
IntDate is always an integer number like this: yyyymmdd

RBS

"pikus " wrote in message
...
Your problem most likely comes from the fact that this code will only
work if intDate has the correct number of digits. Something as simple
as Jan - Sept being given as "1" - "9" instead of "01" - "09" could
cause it to malfunction. - Pikus


---
Message posted from http://www.ExcelForum.com/


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Strange date formatting problem

Then try it like this:

Format(DateSerial(Right(intDate, 2),
Mid(intDate, 5, 2), _
Left(intDate, 4)), "dd/mm/yyyy")


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Strange date formatting problem

That is what I am doing already.

RBS


"pikus " wrote in message
...
Then try it like this:

Format(DateSerial(Right(intDate, 2),
Mid(intDate, 5, 2), _
Left(intDate, 4)), "dd/mm/yyyy")


---
Message posted from http://www.ExcelForum.com/




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Strange date formatting problem

Did you note the change of order? - Pikus


---
Message posted from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Strange date formatting problem

OK, I noticed now, but that just gives me a wrong date altogether.
The function to convert to a date from the integer number yyyymmdd is fine.
This is really puzzeling.

RBS

"pikus " wrote in message
...
Did you note the change of order? - Pikus


---
Message posted from http://www.ExcelForum.com/


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
F2 shortcut and strange formatting of date fields Kate Excel Discussion (Misc queries) 1 July 30th 07 12:10 PM
Date Formatting problem laralea Excel Discussion (Misc queries) 5 January 23rd 06 07:07 PM
Date Formatting Problem Jocko69 Excel Discussion (Misc queries) 3 November 6th 05 06:59 PM
Date formatting problem Anne CFS Excel Discussion (Misc queries) 1 July 19th 05 01:31 PM
Problem with Date Formatting The Data Detective Excel Discussion (Misc queries) 0 March 30th 05 12:57 AM


All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"