Lost time part of datetime datatype

B

bpsdgnews

Hi,

I use this code to ad a record to an SQL server table:

Private Function NieuweTraining(ByVal Tijdstip As Date) As Integer

Dim Training = New tblTrainingen

With Training
.Persoon = frmMain.cboLopers.SelectedValue
.Tijdstip = Tijdstip
End With

dcTraining.tblTrainingens.InsertOnSubmit(Training)
dcTraining.SubmitChanges()

Return Training.Id

End Function

tblTrainingen is a Linq-to-SQL object.

Training.Tijdstip is a datetime column in an SQLserver database

If I put a breakpoint in, Training.Tijdstip will show up with the
timepart in as well (Although it is in AM/PM format, which is not a
usual fromat here in Europe). But if I look in the database later, all
the records will show the date with time set at 0:00:00.

The variable Tijdstip is coming from a third party dll. Is this a
problem in localization? Or is it something else?
 
B

bpsdgnews

Hi,

I use this code to ad a record to an SQL server table:

    Private Function NieuweTraining(ByVal Tijdstip As Date) As Integer

        Dim Training = New tblTrainingen

        With Training
            .Persoon = frmMain.cboLopers.SelectedValue
            .Tijdstip = Tijdstip
        End With

        dcTraining.tblTrainingens.InsertOnSubmit(Training)
        dcTraining.SubmitChanges()

        Return Training.Id

    End Function

tblTrainingen is a Linq-to-SQL object.

Training.Tijdstip is a datetime column in an SQLserver database

If I put a breakpoint in, Training.Tijdstip will show up with the
timepart in as well (Although it is in AM/PM format, which is not a
usual fromat here in Europe). But if I look in the database later, all
the records will show the date with time set at 0:00:00.

The variable Tijdstip is coming from a third party dll. Is this a
problem in localization? Or is it something else?

Okay, to add to this:

I tried something in the immediate window:

tijd = "08-08-2009 14:32"
? tijd
"08-08-2009 14:32"
? cdate(tijd)
#8/8/2009 2:32:00 PM#

So, it seems that date format in vb.net is always AM/PM format.

Still don't understand why I loose the time part in the database
though.
 
A

Armin Zingler

bpsdgnews said:
(Although it is in AM/PM format, which is not a
usual fromat here in Europe).

Unfortunatelly I can only refer to this part but not answer your actual
question. The format displayed is the format for DateTime literals in code:

Dim dt = #8/17/2009 6:57:00 PM#

(which is always English format, otherwise the same source code may not
compile in a different region of the world.) Obviously this format is
also used for displaying DateTime values inside the IDE. Well, kinda
consistent, but a local format would be nice as well.


Armin
 
B

bpsdgnews

Unfortunatelly I can only refer to this part but not answer your actual
question. The format displayed is the format for DateTime literals in code:

        Dim dt = #8/17/2009 6:57:00 PM#

(which is always English format, otherwise the same source code may not
compile in a different region of the world.) Obviously this format is
also used for displaying DateTime values inside the IDE. Well, kinda
consistent, but a local format would be nice as well.

Armin

--https://epetitionen.bundestag.de/index.php?action=petition;sa=details...

Thanks for your comment. I kinda figured that out. And to be precise
it's not an English format, it's a US (and maybe some more countries)
format. The UK uses 24 hr clock just like we do. But I guess it
doesn't matter it is just a way of the IDE to present it. I guess
internally date is just a double type number.

If converted to double the integer part stands for the date and the
decimal part for the time.

I also tried converting mij variable to double in the immediate window
and it shows up properly with the decimals in it.

I feel it must be something in my database, or a bug in Linq to SQL?
 
A

Armin Zingler

bpsdgnews said:
Thanks for your comment. I kinda figured that out. And to be precise
it's not an English format, it's a US (and maybe some more countries)
format. The UK uses 24 hr clock just like we do. But I guess it
doesn't matter it is just a way of the IDE to present it. I guess
internally date is just a double type number.

Didn't even know that about the 24 hr clock in the UK. :-/
If converted to double the integer part stands for the date and the
decimal part for the time.

Internally it's stored as the number of ticks (=100 nano seconds) since
1.1.0001 (see [F1] @ DateTime).
I also tried converting mij variable to double in the immediate window
and it shows up properly with the decimals in it.

How did you convert? CDbl(DateTime) is not valid. DateTime.ToOADate?
Then it does the conversion as described by you above but it's not the
internal storage.
I feel it must be something in my database, or a bug in Linq to SQL?

I've never used LINQ to SQL yet, therefore I have no clue.


Armin
 
B

bpsdgnews

bpsdgnews schrieb:




Thanks for your comment. I kinda figured that out. And to be precise
it's not an English format, it's a US (and maybe some more countries)
format. The UK uses 24 hr clock just like we do. But I guess it
doesn't matter it is just a way of the IDE to present it. I guess
internally date is just a double type number.

Didn't even know that about the 24 hr clock in the UK. :-/
If converted to double the integer part stands for the date and the
decimal part for the time.

Internally it's stored as the number of ticks (=100 nano seconds) since
1.1.0001 (see [F1] @ DateTime).
I also tried converting mij variable to double in the immediate window
and it shows up properly with the decimals in it.

How did you convert? CDbl(DateTime) is not valid. DateTime.ToOADate?
Then it does the conversion as described by you above but it's not the
internal storage.
I feel it must be something  in my database, or a bug in Linq to SQL?

I've never used LINQ to SQL yet, therefore I have no clue.

Armin

--https://epetitionen.bundestag.de/index.php?action=petition;sa=details...- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Yes, I converted with DateTime.ToOADate.

The IDE showed already that the time part wasn't lost in the coding,
but to be sure I wanted to see it as a double. Because I was confused
by the AM/PM format the IDE showed. I'm a hobbyist programmer, and
started out years ago with GWbasic, Quickbasic and my first work in VB
was in version 2!. Now, from that time I don't remember even having a
Date(time) format then. As far as I know it was just longs and
doubles. Guess that's why I always keep thinking about those
datatypes.

I got the feeling that there is not much Linq to SQL in this group.
Are there other groups for this subject?
 
B

bpsdgnews

bpsdgnews schrieb:
Didn't even know that about the 24 hr clock in the UK. :-/
Internally it's stored as the number of ticks (=100 nano seconds) since
1.1.0001 (see [F1] @ DateTime).
I also tried converting mij variable to double in the immediate window
and it shows up properly with the decimals in it.
How did you convert? CDbl(DateTime) is not valid. DateTime.ToOADate?
Then it does the conversion as described by you above but it's not the
internal storage.
I've never used LINQ to SQL yet, therefore I have no clue.

--https://epetitionen.bundestag.de/index.php?action=petition;sa=details...Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -

Yes, I converted with DateTime.ToOADate.

The IDE showed already that the time part wasn't lost in the coding,
but to be sure I wanted to see it as a double. Because I was confused
by the AM/PM format the IDE showed. I'm a hobbyist programmer, and
started out years ago with GWbasic, Quickbasic and my first work in VB
was in version 2!. Now, from that time I don't remember even having a
Date(time) format then. As far as I know it was just longs and
doubles. Guess that's why I always keep thinking about those
datatypes.

I got the feeling that there is not much Linq to SQL in this group.
Are there other groups for this subject?- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Okay, I found out the reason.

If changes are made in the database the Linq to SQL classes are not
updated automatically. There's not even a refresh option in the O/R
designer. I solved it by changing it in the code that was written bhy
the designer. Could have also removed the tbale from the designer and
then put it back in.

It all seems a bit silly to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top