Date Format

Results 1 to 2 of 2

Thread: Date Format

  1. #1
    Greg Strutton Guest

    Default Date Format

    I use an Access Database and to add the date, I use "=Now()" in the database. The problem is it writes the date format in USA and I need it in UK (DD/MM/YYYY). Is there a way around this?

  2. #2
    Join Date
    Dec 1969
    Posts
    569

    Default RE: Date Format

    This is an include file pointed out to me as an article here at Four Guys. I can&#039t find the URL though. So put it in an include file and call the function as such:<BR><BR>strDate = Date()<BR>strEngDate = DanDate(strDate, "%d %B %Y")<BR><BR>It&#039s pretty cool - change the caps on those characters and you get different formats etc.<BR>The following goes in the include file:<BR><BR>&#060;SCRIPT RUNAT=Server LANGUAGE="VBScript"&#062;<BR>Function DanDate (strDate, strFormat)<BR><BR> Dim intPosItem<BR> Dim intHourPart<BR> Dim strHourPart<BR> Dim strMinutePart<BR> Dim strSecondPart<BR> Dim strAMPM<BR><BR> <BR> If not IsDate(strDate) Then<BR> DanDate = strDate<BR> Exit Function<BR> End If<BR> <BR> intPosItem = Instr(strFormat, "%m")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> DatePart("m",strDate) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%m")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%b")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> MonthName(DatePart("m",strDate),True) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%b")<BR> Loop<BR> <BR> intPosItem = Instr(strFormat, "%B")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> MonthName(DatePart("m",strDate),False) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%B")<BR> Loop<BR> <BR> intPosItem = Instr(strFormat, "%d")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> DatePart("d",strDate) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%d")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%j")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> DatePart("y",strDate) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%j")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%y")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> Right(DatePart("yyyy",strDate),2) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%y")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%Y")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> DatePart("yyyy",strDate) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%Y")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%w")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> DatePart("w",strDate,1) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%w")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%a")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> WeekDayName(DatePart("w",strDate,1),True) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%a")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%A")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> WeekDayName(DatePart("w",strDate,1),False) & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%A")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%I")<BR> Do While intPosItem &#062; 0<BR> intHourPart = DatePart("h",strDate) mod 12<BR> if intHourPart = 0 then intHourPart = 12<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> intHourPart & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%I")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%H")<BR> Do While intPosItem &#062; 0<BR> strHourPart = DatePart("h",strDate)<BR> if strHourPart &#060; 10 Then strHourPart = "0" & strHourPart<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> strHourPart & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%H")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%M")<BR> Do While intPosItem &#062; 0<BR> strMinutePart = DatePart("n",strDate)<BR> if strMinutePart &#060; 10 then strMinutePart = "0" & strMinutePart<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> strMinutePart & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%M")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%S")<BR> Do While intPosItem &#062; 0<BR> strSecondPart = DatePart("s",strDate)<BR> if strSecondPart &#060; 10 then strSecondPart = "0" & strSecondPart<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> strSecondPart & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%S")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%P")<BR> Do While intPosItem &#062; 0<BR> if DatePart("h",strDate) &#062;= 12 then<BR> strAMPM = "PM"<BR> Else<BR> strAMPM = "AM"<BR> End If<BR> strFormat = Left(strFormat, intPosItem-1) & _<BR> strAMPM & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%P")<BR> Loop<BR><BR> intPosItem = Instr(strFormat, "%%")<BR> Do While intPosItem &#062; 0<BR> strFormat = Left(strFormat, intPosItem-1) & "%" & _<BR> Right(strFormat, Len(strFormat) - (intPosItem + 1))<BR> intPosItem = Instr(strFormat, "%S")<BR> Loop<BR><BR> DanDate = strFormat<BR> <BR>End Function<BR>&#060;/SCRIPT&#062;<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •