Format a date to a as short a string as possible


/ Published in: ASP
Save to your folder(s)

Todays dates are shown as hh:mm, dates from yesterday and earlier as dd mmm.
This can be useful, since recent dates are showing more details


Copy this code and paste it in your HTML
  1. <%
  2. function FormDate(datum)
  3. if datum & "" = "" then FormDate="onbekend" : exit function
  4. if datum = "1-1-1900" then FormDate="-nooit-" : exit function
  5. hulp=split(replace(datum,"/","-") & ""," ")
  6. if UBound(hulp)<1 then FormDate=datum & " !" : exit function
  7. tijd=split(hulp(1),":")
  8. if UBound(tijd)<2 then FormDate=datum & " !" : exit function
  9. dag=split(hulp(0),"-")
  10. if UBound(dag)<2 then FormDate=datum & " !" : exit function
  11. if instr(datum,"/")>0 then hulp=dag(1) : dag(1)=dag(0) : dag(0)=hulp
  12. if len(dag(1))=1 then dag(1)="0" & dag(1)
  13. dag(1)=mid("XXJanFebMrtAprMeiJunJulAugSepOktNovDec",dag(1)*3,3)
  14. if len(tijd(0))=1 then tijd(0)="0" & tijd(0)
  15. if len(tijd(1))=1 then tijd(1)="0" & tijd(1)
  16. if len(dag(0))=1 then dag(0)="0" & dag(0)
  17. if datum>=date() then
  18. FormDate=tijd(0) & ":" & tijd(1) & "u"
  19. else
  20. if year(datum)=year(date()) then
  21. FormDate=dag(0) & "-" & dag(1) & " " ' & tijd(0) & ":" & tijd(1) & "u"
  22. else
  23. FormDate=dag(0) & "-" & dag(1) & "-" & dag(2) & " " ' & tijd(0) & ":" & tijd(1) & "u"
  24. end if
  25. end if
  26. end function
  27. %>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.