Avatar billede n_riber Nybegynder
10. juli 2001 - 18:08 Der er 24 kommentarer og
1 løsning

Hvordan kan jeg konvertere et dato klokkeslæt felt til et tal felt

Jeg vil have konverteret et kort klokkeslet eks 01:36 til et tal i dette tilfælde 96

Hvordan gør jeg dette ??
Avatar billede blazer Nybegynder
10. juli 2001 - 18:14 #1
vil ikke lave noget specifikt til dig..men her er det i grove træk det du skal alve..lav en ny kolonne som du sætter til at være tal...lav en makro den makro skal så læse rs(\"Tid\") og så køre noget i retning af

temparr=split(rs(\"tid\"),\":\"))
Tal=(Temparr(0)*60)+temparr(1)
rs(\"Tal\")=Tal

så til sidst sletter du bare tid om omdøber tal til tid....hvis du ikke fatter d..så bare spørg på icq 83294654

Avatar billede terry Ekspert
11. juli 2001 - 09:03 #2
Dim lResult As Long
Dim tTime As Date

    tTime = \"1999-01-01 13:42:50\"
   
    lResult = DatePart(\"h\", tTime) * 60 + DatePart(\"n\", tTime)

Avatar billede n_riber Nybegynder
11. juli 2001 - 10:46 #3
It won\'t work, this is what i wrote:

dim konverter_Sani as long
dim difference_sanitid as date

difference_sanitid=\"1999-01-01 13:42:50\"
konverter_sani=datepart(\"h\",difference_sanitid)*60 + datepart(\"n\",Difference_sanitid)

it returns nothing, and no errors
Avatar billede terry Ekspert
11. juli 2001 - 10:54 #4
the example I sent does work! Are you doing this in Access?

if you debug the code cant you see what is not working?
Does difference_sanitid contain a date?
Does the datepart parts return anything?
Does konverter_sani contain anything?

Avatar billede n_riber Nybegynder
11. juli 2001 - 10:58 #5
Difference_sanitid contains \"hh:mm\" \"short time format?\"
konverter_sani doesn\'t contain anything
Avatar billede terry Ekspert
11. juli 2001 - 11:06 #6
are you saying that there is no date in difference_sanitid?

while debugging, if you highlight the datepart(\"h\",difference_sanitid) and then select Quick Watch (the glasses) from the menu bar, does it contain anything?
Avatar billede n_riber Nybegynder
11. juli 2001 - 11:10 #7
difference_sanitid only contains a time like this \"01:30\"
Avatar billede terry Ekspert
11. juli 2001 - 11:16 #8
Try altering the format of the date part of difference_sanitid
for example \"30-12-1999 13:42:50\"

This sounds VERY strange!!

You can send your dB to dktebrsa@europe.lego.com

and I will take a look
Avatar billede n_riber Nybegynder
11. juli 2001 - 13:18 #9
Hi Terry,
i found another solution but now i have another problem are you up fore the chalenge
Avatar billede n_riber Nybegynder
11. juli 2001 - 13:18 #10
fore = for
Avatar billede terry Ekspert
11. juli 2001 - 13:30 #11
yes, why not!
Avatar billede n_riber Nybegynder
11. juli 2001 - 13:36 #12
i have two fields, type; standard date/time format they both contain time expressions like \"23:50:00\" and \"00:35:00\", when i add field1 and field2 in field3 i get an result like this \"31-12-1899 00:25:00\" in the record that crosses midnight

How can i correct this?
Avatar billede terry Ekspert
11. juli 2001 - 13:47 #13
What are you expecting from adding the two times together? 23:50:00\" + \"00:35:00\" = \"00:25:00\"

You are aware that in the datetime field there will be something in the date part?

Avatar billede n_riber Nybegynder
11. juli 2001 - 14:25 #14
I  know that the result is correct, but it is only in the record that crosses midnight, that the date part appears, therefore i was wondering if it would be possible to format field3 ?
Avatar billede terry Ekspert
11. juli 2001 - 15:04 #15
I dont know how your getting your time into these fields but would think that the problem is because your adding two fields together which actaully contain a date and a time even if you didnt put one there yourself, even though you are only interested in the time part.

If you are showing the result in a field you can alter the format property for the field to a long time format and you wont see the date part. Or you can make query which only shows the time part.

Avatar billede n_riber Nybegynder
11. juli 2001 - 15:23 #16
Field1 is created by user ex. \"23:50\" field2 is created from user selecting how many minutes proces 1 is taking ex. \"35\" this is selection is transformed into another field as an datetime \"00:35:00\" none of these fields seem to contain a date, in my form it\'s only the record that has a start time before midnight and an endtime after midnight that is causing the trouble.
Avatar billede n_riber Nybegynder
11. juli 2001 - 15:25 #17
the field does only show the time part, but i need the value of the field in other functions, therefore i need the field to be only time related
Avatar billede terry Ekspert
11. juli 2001 - 15:35 #18
This is taken from Access help.

Date variables are stored as IEEE 64-bit (8-byte) floating-point numbers that represent dates ranging from 1 January 100 to 31 December 9999 and times from 0:00:00 to 23:59:59. Any recognizable literal date values can be assigned to Date variables. Date literals must be enclosed within number signs (#), for example, #January 1, 1993# or #1 Jan 93#.
Date variables display dates according to the short date format recognized by your computer. Times display according to the time format (either 12-hour or 24-hour) recognized by your computer.

When other numeric types are converted to Date, values to the left of the decimal represent date information while values to the right of the decimal represent time. Midnight is 0 and midday is 0.5. Negative whole numbers represent dates before 30 December 1899.


So you can assign a datetime field almost any value and it will convert it to something. If you will use a datetime field for storing your time values then it is going to give you the problems your having. You can make a query where you only take the HH:MM parts and tehn calculate these fields but if youuse date functions to calculate then you will be making problems for yourself.

YOU CANT GET AWAY FROM THE FACT THAT THERE IS A DATE (of some sort)IN YOU FIÈLDS!!
Avatar billede n_riber Nybegynder
11. juli 2001 - 15:45 #19
I found the solution, i just need to format the field after the datetimevalue has been inserted. like this  me.fieldmane=format(fieldname,\"hh:mm:ss\".
and the date part is gone

Avatar billede n_riber Nybegynder
11. juli 2001 - 15:45 #20
I found the solution, i just need to format the field after the datetimevalue has been inserted. like this  me.fieldmane=format(fieldname,\"hh:mm:ss\".
and the date part is gone
Avatar billede n_riber Nybegynder
11. juli 2001 - 15:46 #21
me.fieldmane=fieldname
Avatar billede terry Ekspert
11. juli 2001 - 15:51 #22
SELECT tbldates.newdate, DatePart(\"h\",[newdate]) AS h, Format([newdate],\"hh\") AS hh, DatePart(\"n\",[newdate]) AS m, Format([newdate],\"nn\") AS mm, Format([newdate],\"ss\") AS ss, Format([newdate],\"hh:nn:ss\") AS hhmmss
FROM tbldates;

you need to alter the table and field names so you can see hwo thing sare done with the datepart and format functions
Avatar billede n_riber Nybegynder
11. juli 2001 - 15:53 #23
you knockeed me of my chair there, i don\'t quite follow
Avatar billede terry Ekspert
11. juli 2001 - 16:14 #24
Ït was just an example of various ways to use Datepart and format to show date and time fields.

For your field it would look something like this>

SELECT  Format([fieldname],hh:nn:ss\") AS hhmmss
FROM table;

or on a form>
me.fieldname=format(fieldname,\"hh:nn:ss\")




Avatar billede n_riber Nybegynder
11. juli 2001 - 16:16 #25
thankx, for the help
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
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

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