[ASP] Datum en tijd weergeven met 0.

Pagina: 1
Acties:

  • Tommel
  • Registratie: November 2000
  • Niet online
Ik ben met een site bezig waar ook datum en tijd items in voorkomen.
Nu wil ik dat wanneer een datum de dag of maand kleiner is als 10 er een nul voor de dag of maand komt, zijn hier standaard functies voor ??
Met FormatDateTime werkt het niet.

voorbeeld

code:
1
2
3
4
5
8-3-2002

moet worden

08-03-2002

  • Juup
  • Registratie: Februari 2000
  • Niet online
heeft ASP een soort van printf, formatted print functie?
Of een contructie als ? :
bv (number < 10) ? print 0 : print '';

Een wappie is iemand die gevallen is voor de (jarenlange) Russische desinformatiecampagnes.
Wantrouwen en confirmation bias doen de rest.


  • WimB
  • Registratie: Juli 2001
  • Laatst online: 30-03-2024
Dit zou het moeten doen:
code:
1
MyStr = Format(MyDate, "dd mm  yyyy")

MyDate is de invoer en MyStr de uitvoer ;)

edit:

Zo is het helemaal juist:
MyStr = Format(MyDate, "dd-mm-yyyy")

.

  • Tommel
  • Registratie: November 2000
  • Niet online
WimB schreef op 05 augustus 2002 @ 17:54:

Zo is het helemaal juist:
MyStr = Format(MyDate, "dd-mm-yyyy")
Hij kent de Format functie helemaal niet ??

  • Crazy D
  • Registratie: Augustus 2000
  • Laatst online: 09:31

Crazy D

I think we should take a look.

ASP kent geen Format, kijk eens naar de FormatDateTime functie, misschien kun je daar wat mee. Alternatief is zelf de boel opsplitsen, dus iets als
Right("00" & Day(dedatum), 2) & Right("00" & Month(dedatum), 2) & Year(dedatum)

Exact expert nodig?


  • zneek
  • Registratie: Augustus 2001
  • Laatst online: 08-02-2025
http://msdn.microsoft.com.../728/msdncompositedoc.xml

VBScript reference. Zoek de goeie functie maar eens, hij bestaat. FormatDateTime oid.

  • -SaveMe-
  • Registratie: Januari 2002
  • Laatst online: 24-07 14:02

-SaveMe-

-klik-

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Function VoorLoopNul(waarde)
    if Not IsNumeric(waarde) or IsNull(waarde) or waarde="" then
        VoorLoopNul=""
        exit function
    end if
    if Rtrim(cint(waarde)) < 10 then
        VoorLoopNul = "0" & waarde
    else 
        VoorLoopNul = waarde
    end if
end function


Function DateNl(date)
dim maand, dag
    if IsNull(date) or date="" then
        DateNl = "&nbsp;"
        exit function
    end if
    maand = Month(date)
    'if maand < 10 then maand = "0" & maand
    dag = Day(date)
    'if dag < 10 then dag = "0" & dag
    DateNl =  VoorLoopNul(dag) & "-" & VoorLoopNul(maand) & "-" & year (date)
end function


De twee functions in een betsand stoppen dat je include.
aanroepen met dateNl(jedatumhiero) waar gewenst ;)

zoiets ?

GamiQ, de game notes app met game maps!


  • akakiwi
  • Registratie: September 2000
  • Laatst online: 20-03 11:13

akakiwi

I believe in the ruling class.

Zo heb ik dat ook gedaan. Gewoon een functie geschreven die het afhandeld.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function fnFormatDate(vDate)
    dim aIntegers
    dim iCount

    aIntegers = split(cstr(day(vDate)) & "," & cstr(month(vDate)) & "," & cstr(year(vDate)), ",")
    for iCount = 0 to ubound(aIntegers)
        if aIntegers(iCount) < 10 then
            aIntegers(iCount) = "0" & cstr(aIntegers(iCount))
        else
            aIntegers(iCount) = cstr(aIntegers(iCount))
        end if
    next
    fnFormatDate = aIntegers(0) & "-" & aIntegers(1) & "-" & aIntegers(2)
end function

function fnFormatTime(vTime)
    dim aIntegers
    dim iCount

    aIntegers = split(cstr(hour(vTime)) & "," & cstr(minute(vTime)) & "," & cstr(second(vTime)), ",")
    for iCount = 0 to ubound(aIntegers)
        if aIntegers(iCount) < 10 then
            aIntegers(iCount) = "0" & cstr(aIntegers(iCount))
        else
            aIntegers(iCount) = cstr(aIntegers(iCount))
        end if
    next
    fnFormatTime = aIntegers(0) & ":" & aIntegers(1)' & ":" & aIntegers(2)
end function


Zowel om de tijd als om de datum goed op te maken.

| Life is a game (and games are fun) | homepage |


  • Scharnout
  • Registratie: November 2000
  • Laatst online: 23-08 12:39

Scharnout

Meuk

Mooie functies, maar de optie van Crazy D komt het best in de buurt als makkelijk, maar dan anders :)

Probeer dit eens, altijd prijs!

code:
1
TempDate = DatePart("yyyy",TempDate) & "-" & right("0" & DatePart("m",TempDate),2) & "-" & right("0" & DatePart("d",TempDate),2)


Deze zet de datum neer yyy-mm-dd (anders trok MySQL het niet)

Stuk simpeler dan al die lappen tekst :+

And Bob's your uncle ...


  • Crazy D
  • Registratie: Augustus 2000
  • Laatst online: 09:31

Crazy D

I think we should take a look.

Scharnout schreef op 06 augustus 2002 @ 14:39:
Mooie functies, maar de optie van Crazy D komt het best in de buurt als makkelijk, maar dan anders :)
:D ok "0" & is genoeg, omdat als het een geldige datum is, je altijd minimaal 1 positie gevuld hebt :)
Of DatePart of de Day, Month en Year functies iets uitmaakt weet ik eigenlijk niet. Ben niet zo'n datum freak :P

Exact expert nodig?

Pagina: 1