---
title: "Datumformatering"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/61763-datumformatering"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Erik Juhlin"
published: "2002-12-10T08:30:52.000Z"
updated: "2002-12-13T08:33:45.000Z"
replies: 1
views: 1108
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/61763-datumformatering"
---

# Datumformatering

## #1 — Erik Juhlin, 2002-12-10T08:30Z

Ett försök till att göra datumformatering lite enklare. Har härmat Format funktionen i VB. :)

```
<%
Function Format(dDate, sFormat)
	dDate = CDate(dDate)
	sFormat = Replace(sFormat, "YYYY", Right("0000" & Year(dDate), 4), 1, -1, 1)
	sFormat = Replace(sFormat, "MM", Right("00" & Month(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "M", Month(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "DD", Right("00" & Day(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "D", Day(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "HH", Right("00" & Hour(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "H", Hour(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "NN", Right("00" & Minute(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "N", Minute(dDate), 1, -1, 1)
	sFormat = Replace(sFormat, "SS", Right("00" & Second(dDate), 2), 1, -1, 1)
	sFormat = Replace(sFormat, "S", Second(dDate), 1, -1, 1)
	Format = sFormat
End Function

Response.Write Format(Now, "YYYY-MM-DD HH:NN:SS.000") & "<br>"
Response.Write Format(Now, "H:NN - D / M, YYYY") & "<br>"
Response.Write Format(Now, "Kl. HH:NN:SS") & "<br>"
%>
```

Permalänk: https://www.webforum.nu/p/61763

## #2 — Vide, 2002-12-13T08:33Z

Har gjort en liknande funktion: <http://www.webeye.nu/default2.asp?que=asp/format.asp>

Dock är det ganska mycket mer kod, men innehåller lite fler "funktioner". ;)

Mvh, Vide

Permalänk: https://www.webforum.nu/p/885033

---

Tråden på webben: https://www.webforum.nu/amne/asp/61763-datumformatering
