Avatar billede aerobee Nybegynder
09. juli 2005 - 16:09 Der er 8 kommentarer og
1 løsning

FormatDateTime(Now, vbShortTime)

Hejsa.

Hvordan kan jeg integrere "FormatDateTime(Now, vbShortTime)"
i følgende sql sætning:

sql ="INSERT INTO Breve (BrugerID,AfsenderID,Emne,Post,Dato,Hour,Minute,Time) VALUES ("&""&id&","&Session("bruger")&",'"&top&"','"&send&"','"&CDATE(Date())&"','"&Hour(Time())&"','"&Minute(Time())&"')"

Har prøvet nogle forskellige metoder men kan ikke få det til at virke.. Her er en af dem jeg har prøvet:

sql ="INSERT INTO Breve (BrugerID,AfsenderID,Emne,Post,Dato,Hour,Minute,Time) VALUES ("&""&id&","&Session("bruger")&",'"&top&"','"&send&"','"&CDATE(Date())&"','"&Hour(Time())&"','"&Minute(Time())&"','"&FormatDateTime(Now, vbShortTime)&"')"

Men det dur bare ikke det skidt...
Avatar billede aerobee Nybegynder
09. juli 2005 - 16:10 #1
Jeg får en syntax error på ovenstående metode som jeg har prøvet.
Avatar billede terry Ekspert
09. juli 2005 - 16:39 #2
If you are using Access as your database then dates are always stored in the same way. vbShortTime will have ne effect!

Its also best to insert the date in yyyy-mm-dd format

so

INSERT INTO Breve .....'2005-07-09 16:38'....

should work
Avatar billede aerobee Nybegynder
09. juli 2005 - 16:49 #3
What i need is to get the time ONLY printed to my database as xx:xx nothing else but i am having difficulties doing it in my sql.. I have allready done the date ages ago..
Have used this until now '"&Minute(Time())&"' and works like a charm. But when the minute is 1 to 9 it only prints 1, and i need it to print 01 thats why this question is here
Avatar billede aerobee Nybegynder
09. juli 2005 - 17:49 #4
Sorry to reject your answer terry, but i really cant use it.

Yes i use an access databse and the field "Time" in the table "Breve", is set to Date/Time - ShortTime and thats what i need (xx:xx).
But my problem is i cant figure out how to write it in to the sql, cause im pretty sure i need to format the number, with vbShortTime to get the desired result.
The sql is set to execute after clicking on a link, (a link where you send a new email), and i need a timestamb with that and offcourse the date, wich i have allready done.
Avatar billede aerobee Nybegynder
09. juli 2005 - 17:58 #5
What i use now as you can see on the above is
'"&Hour(Time())&"','"&Minute(Time())&"' and that works. I get my desired result xx:xx when i drag the numbers out of the database.
But when the minute is 1 as an example it gives me the result 1 and i need the result 01. Can you see what i mean? 14:01 looks better than 14:1 hehe :)
Thats why i need the vbShortTime as that will provide me with the desired result.
Avatar billede aerobee Nybegynder
09. juli 2005 - 18:34 #6
I have solved the problem myself. My erro was i used a reserved word in the Database (Time) hehe :)

Thanks for the participation :)
Avatar billede terry Ekspert
10. juli 2005 - 10:09 #7
Sorry for noty getting back, busy with other things.
If you used reserved words in Access just enclose it with [] and it works.

As I mentioned, dates (and times) are always stored in the same way in the database and has NO effect on how you show them.
To display dates differently you can I think in VBScript use

format([time], "HH:MM")
Avatar billede aerobee Nybegynder
10. juli 2005 - 10:12 #8
Allright terry, thanks for the tip :)

Do you want some points ?
Avatar billede terry Ekspert
10. juli 2005 - 10:23 #9
No, you solved your own problem, and I have enough thanks.

Have a nice day :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester