Jump to content

[Resolvido] Subtrair DateTime


EdiSimoes
 Share

Recommended Posts

Alguem poderia me ajudar a subtrair uma data no vb e BD sqlServer 2008.

Tenho dois campos datetime, SAIDA e CHEGADA, onde são guandado a data e hora de saida / e data e hora de chegada.

Agora tenho que clicar em um botão e atualizar a chegada e calcular o tempo de viagem e atualizar o terceiro campo que seria o TOTAL da viagem.

Desde ja agradeço a cooperação de todos.

Edi Carlos Simões

Estudante de Análise e Desenvolvimento de Sistemas

edisimoes@bol.com.br

http://www.desenvolvenetma.com.br

http://analisedesistemas.bl.ee

Link to comment
Share on other sites

E como passo esse código para Visual Basic???

try {
DateTime dt1 = DateTime.Now;
DateTime dt2 = new DateTime (2003,4,15);
TimeSpan ts = dt1.Subtract (dt2);
Console.WriteLine (ts);
} catch (Exception ex) {
Console.WriteLine ( ex.Message);
}
Edited by ribeiro55

Edi Carlos Simões

Estudante de Análise e Desenvolvimento de Sistemas

edisimoes@bol.com.br

http://www.desenvolvenetma.com.br

http://analisedesistemas.bl.ee

Link to comment
Share on other sites

achei um exemplo em VB.NET:

http://stackoverflow...other-in-vb-net

ou aqui:

'June 20th at 1am.>>
Dim dt2 As DateTime = Convert.ToDateTime("06/20/2008 01:00:00")
'June 19th at 16:00 or 4pm.>>
Dim dt1 As DateTime = Convert.ToDateTime("06/19/2008 16:00:00")

'Use a TimeSpan like this.>>
Dim ts As New TimeSpan
ts = dt2.Subtract(dt1)
MessageBox.Show("Hours difference = " & ts.Hours.ToString)

'or use DateDiff like this.>>
Dim diff As Long = DateDiff(DateInterval.Hour, dt2, dt1)
MessageBox.Show("Hours difference = " & ts.Hours.ToString)

Edited by ribeiro55

Fernando Lage Bastos - MCP/MCTS/MCPD

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.