format date/time excel in Vb.net

  • Thread starter Thread starter pp
  • Start date Start date
P

pp

I have this kind of format dates "02-01-2001 16:00" in a excel
spreadsheet (dd-mm-aaaa h:mm).

In vb.net I have this code:
Dim tempo As string
tempo=oExcelWs.Cells(i, 1).Value

and I get this date: tempo = "01-02-2001 16:00", the code have switched
the month whit the day.

Can anyone help me?
Thanks
Paulo Praça
 
PP,

I dont know if it helps you, however you can try it.

(I think that you have option strict off, better is to set it on)

dim tempodt as datetime = Ctype(oExcelWs.Cells(i, 1).Value,datetime)

Than you get a datetime that you can use in any format you want by using the
tostring method.

dim tempo as string = tempodt.tostring(d) ' by instance

I hope this helps (I am not sure, just a guess however not without to know
something about it).

Cor
 
Cor said:
PP,

I dont know if it helps you, however you can try it.

(I think that you have option strict off, better is to set it on)

dim tempodt as datetime = Ctype(oExcelWs.Cells(i, 1).Value,datetime)

Than you get a datetime that you can use in any format you want by using the
tostring method.

dim tempo as string = tempodt.tostring(d) ' by instance

I hope this helps (I am not sure, just a guess however not without to know
something about it).

Cor
Thanks Cor
PP
 

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

Back
Top