Hi there,
Could someone please help me with a problem that I thought would be very simple to solve but which is actually turning out to be a real pain and it must be my lack of understanding.
I have a function that basically determines the number of minutes between 2 passed dates. This works fine on my clients systems (regional settings doe date are US format)but does not work correctly on my systems which have the regional setting for dates to be UK format.
I obviously wanted to develop the software (the program is actually called from a system service) so that It would be independant of the actual regional settings of the PC it was running on and so decided to always work in American date format within VB (i.e. MM/DD/YYYY HH:NN:SS).
Thus, the code gets 2 dates from a database table and then uses the format function to put them into MM/DD/YYYY hh:nn:ss format. I then use cdate() to convert the strings into a date variable. These 2 date variable are then passed to the comparison function.
The problem that I am having is that when the software runs on my systems, using a UK date format, the datediff function is using the UK regional settings and so if the 2 dates from the database table have an a difference of 1 day, the datedfiff function thinks there is actaully a difference of 1 month!!
Thus if I pass the function the dates of (in US format):-
06/07/2007 23:45:00
and
06/08/2007 00:45:00
There is a difference of 60 minutes between the above 2 dates/times but the datediff function returns a number which is the number of minutes difference in the month. Thus it is obviously using the middle 2 digits for the month.
I have tried passing the dates as date literals and putting # around them, so that the system will always see the date in US format, but when I do this I get a type mismatch error, as I suppose by adding the "#" onto each end of the cdate() fucntion I am changing it back into a string?
This is what I tried :-
dim first_date as date
dim second_date as date
' dbdate1 and dbdsate2 reference database table collection fields
first_date = "#" & cdate(format(dbdate1),"MM/DD/YYYY hh:nn:ss") & "#"
second_date = "#" & cdate(format(dbdate2),"MM/DD/YYYY hh:nn:ss") & "#"
minutes_difference = get_minutes_difference(date1 as date, date2 as date)
end
private function get_minutes_difference(date1 as date,date2 as date)
get_minutes_difference = datediff(date1,date2)
return
This gives me a type msimatch error on the call to the get_minutes_difference function
Any pointers would be muich appreciated.
Thanks
Newora
Could someone please help me with a problem that I thought would be very simple to solve but which is actually turning out to be a real pain and it must be my lack of understanding.
I have a function that basically determines the number of minutes between 2 passed dates. This works fine on my clients systems (regional settings doe date are US format)but does not work correctly on my systems which have the regional setting for dates to be UK format.
I obviously wanted to develop the software (the program is actually called from a system service) so that It would be independant of the actual regional settings of the PC it was running on and so decided to always work in American date format within VB (i.e. MM/DD/YYYY HH:NN:SS).
Thus, the code gets 2 dates from a database table and then uses the format function to put them into MM/DD/YYYY hh:nn:ss format. I then use cdate() to convert the strings into a date variable. These 2 date variable are then passed to the comparison function.
The problem that I am having is that when the software runs on my systems, using a UK date format, the datediff function is using the UK regional settings and so if the 2 dates from the database table have an a difference of 1 day, the datedfiff function thinks there is actaully a difference of 1 month!!
Thus if I pass the function the dates of (in US format):-
06/07/2007 23:45:00
and
06/08/2007 00:45:00
There is a difference of 60 minutes between the above 2 dates/times but the datediff function returns a number which is the number of minutes difference in the month. Thus it is obviously using the middle 2 digits for the month.
I have tried passing the dates as date literals and putting # around them, so that the system will always see the date in US format, but when I do this I get a type mismatch error, as I suppose by adding the "#" onto each end of the cdate() fucntion I am changing it back into a string?
This is what I tried :-
dim first_date as date
dim second_date as date
' dbdate1 and dbdsate2 reference database table collection fields
first_date = "#" & cdate(format(dbdate1),"MM/DD/YYYY hh:nn:ss") & "#"
second_date = "#" & cdate(format(dbdate2),"MM/DD/YYYY hh:nn:ss") & "#"
minutes_difference = get_minutes_difference(date1 as date, date2 as date)
end
private function get_minutes_difference(date1 as date,date2 as date)
get_minutes_difference = datediff(date1,date2)
return
This gives me a type msimatch error on the call to the get_minutes_difference function
Any pointers would be muich appreciated.
Thanks
Newora