Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Display

Status
Not open for further replies.

mousematt

MIS
Feb 5, 2001
102
0
0
GB
I'm in the middle of developing a web app that needs to do some date calculations, but IIS insists on showing dats in american format even when the regional settings say UK, this is a big problem as the date going in are UK style(dd/mm/yy)

Any ideas on how to get it to show the date in uk style?
 
format the date before you do your calculations. I found the following function that acts as a format function for dates, pass in the date and the format you want it in and it returns it to you in that format:
(I take it this is not being done in VB as VB has its won Format function)

Function fnFormatDate(dtDate, strFormat)

' the VBScript function FormatDateTime depends on system settings,
' we want to be independent from that and emulate the VB Format Function

' dtDate = the date for format
' strFormat = the format as in the VB Format function
' returns as string with the formatted date

On Error Resume Next
'on error goto 0
'err.clear

Dim arMonths, strTheDate


If Not IsDate(dtDate) Then

strTheDate = "invalid date"

Else

strTheDate = strFormat
If Instr(strTheDate,"dd") Then
If Day(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"dd",cstr(Day(dtDate)))
Else
strTheDate = Replace(strTheDate,"dd","0" & cstr(Day(dtDate)))
End If
End If

If Instr(strTheDate,"d") Then
strTheDate = Replace(strTheDate,"d",cstr(Day(dtDate)))
End If

If Instr(strTheDate,"mmmm") Then
arMonths = Array("January","February","March","April","May","June","July","August","September","October","November","December")
strTheDate = Replace(strTheDate,"mmmm",cstr(arMonths(Month(dtDate)-1)))

ElseIf Instr(strTheDate,"mmm") Then
arMonths = Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
strTheDate = Replace(strTheDate,"mmm",cstr(arMonths(Month(dtDate)-1)))

ElseIf Instr(strTheDate,"mm") Then
'strTheDate = Replace(strTheDate,"mm",cstr(Month(dtDate)))
If Month(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"mm",cstr(Month(dtDate)))
Else
strTheDate = Replace(strTheDate,"mm","0" & cstr(Month(dtDate)))
End If
ElseIf Instr(strTheDate,"m") Then
' If Month(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"m",cstr(Month(dtDate)))
' Else
' strTheDate = Replace(strTheDate,"m","0" & cstr(Month(dtDate)))
' End If
End If

If Instr(strTheDate,"yyyy") Then
strTheDate = Replace(strTheDate,"yyyy",cstr(Year(dtDate)))

ElseIf Instr(strTheDate,"yy") Then
strTheDate = Replace(strTheDate,"yy",Right(cstr(Year(dtDate)),2))
End If

End If

' return the string
If Err.number = 0 Then
fnFormatDate = strTheDate
Else
fnFormatDate = Err.description
Err.Clear
End If

End Function
 
format the date before you do your calculations. I found the following function that acts as a format function for dates, pass in the date and the format you want it in and it returns it to you in that format:
(I take it this is not being done in VB as VB has its own Format function)

Function fnFormatDate(dtDate, strFormat)

' the VBScript function FormatDateTime depends on system settings,
' we want to be independent from that and emulate the VB Format Function

' dtDate = the date for format
' strFormat = the format as in the VB Format function
' returns as string with the formatted date

On Error Resume Next
'on error goto 0
'err.clear

Dim arMonths, strTheDate


If Not IsDate(dtDate) Then

strTheDate = "invalid date"

Else

strTheDate = strFormat
If Instr(strTheDate,"dd") Then
If Day(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"dd",cstr(Day(dtDate)))
Else
strTheDate = Replace(strTheDate,"dd","0" & cstr(Day(dtDate)))
End If
End If

If Instr(strTheDate,"d") Then
strTheDate = Replace(strTheDate,"d",cstr(Day(dtDate)))
End If

If Instr(strTheDate,"mmmm") Then
arMonths = Array("January","February","March","April","May","June","July","August","September","October","November","December")
strTheDate = Replace(strTheDate,"mmmm",cstr(arMonths(Month(dtDate)-1)))

ElseIf Instr(strTheDate,"mmm") Then
arMonths = Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
strTheDate = Replace(strTheDate,"mmm",cstr(arMonths(Month(dtDate)-1)))

ElseIf Instr(strTheDate,"mm") Then
'strTheDate = Replace(strTheDate,"mm",cstr(Month(dtDate)))
If Month(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"mm",cstr(Month(dtDate)))
Else
strTheDate = Replace(strTheDate,"mm","0" & cstr(Month(dtDate)))
End If
ElseIf Instr(strTheDate,"m") Then
' If Month(dtDate) > 9 Then
strTheDate = Replace(strTheDate,"m",cstr(Month(dtDate)))
' Else
' strTheDate = Replace(strTheDate,"m","0" & cstr(Month(dtDate)))
' End If
End If

If Instr(strTheDate,"yyyy") Then
strTheDate = Replace(strTheDate,"yyyy",cstr(Year(dtDate)))

ElseIf Instr(strTheDate,"yy") Then
strTheDate = Replace(strTheDate,"yy",Right(cstr(Year(dtDate)),2))
End If

End If

' return the string
If Err.number = 0 Then
fnFormatDate = strTheDate
Else
fnFormatDate = Err.description
Err.Clear
End If

End Function
 
Being in the UK I have exactly the same problem with the date formatting displaying as mm/dd/yy even though the machines and the server are all set to british date format...

Did you find a better way of doing this rather than the huge code that guy posted?

Is there a ... "Make Microsoft Realise that other countries apart from the US of A use Microsoft Products" type checkbox?

Cheers
Glyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top