Date time exception

mandargholap

Member
Licensed User
Longtime User
I have small code to get the backdate but when I m running this program I get Parse Exception : Unparseable Date "06/02/2012"

Dim strCurrentDate As String
Dim strDate As String, strTime As String
Dim strBackDate As String
Dim lnCurrentDate As Long

DateTime.DateFormat ="dd-MM-yyyy HH:mm:ss"
strCurrentDate = DateTime.Date(DateTime.Now)
'lnCurrentDate = DateTime.DateParse(strCurrentDate)
Msgbox( strCurrentDate, "Right Now it is")

DateTime.DateFormat ="mm/dd/yyyy HH:mm:ss"
strCurrentDate = DateTime.Date(DateTime.Now)
strDate = strCurrentDate.SubString2(0,strCurrentDate.IndexOf(" "))
strTime = strCurrentDate.SubString(strCurrentDate.IndexOf(" "))
lnCurrentDate =DateTime.TimeParse(strTime)
lnCurrentDate= DateTime.DateParse(strDate)
DateTime.DateFormat ="dd-MM-yyyy HH:mm:ss"
strBackDate = DateTime.Date((lnCurrentDate/1000)-3600)
Msgbox( strBackDate, "One Hour before")

Thanks
 

Mahares

Expert
Licensed User
Longtime User
I commented the line that gave you the error and the lines that are not necessary. Here is the complete functional code:

B4X:
Dim strCurrentDate As String
Dim strDate As String, strTime As String
Dim strBackDate As String
Dim lnCurrentDate As Long

DateTime.DateFormat ="dd-MM-yyyy HH:mm:ss" 
strCurrentDate = DateTime.Date(DateTime.Now)
Msgbox( strCurrentDate, "Right Now it is")

'DateTime.DateFormat ="mm/dd/yyyy HH:mm:ss"
strCurrentDate = DateTime.Date(DateTime.Now)
strDate = strCurrentDate.SubString2(0,strCurrentDate.IndexOf (" "))
strTime = strCurrentDate.SubString(strCurrentDate.IndexOf(" ")) 
lnCurrentDate =DateTime.TimeParse(strTime)
'lnCurrentDate= DateTime.DateParse(strDate)
'DateTime.DateFormat ="dd-MM-yyyy HH:mm:ss"
'strBackDate = DateTime.Date((lnCurrentDate/1000)-3600)  'Bad line
strBackDate = DateTime.Date(lnCurrentDate-3600*1000)
Msgbox( strBackDate, "One Hour before")
 
Upvote 0

mandargholap

Member
Licensed User
Longtime User
Thanks Mahares.

But when I am running this code actually even date is going back by 1 day along with time. means current time as "04-06-2012 05:05:29" and time before 1 hour as "03-06-2012 04:06:20"

Can u please help.

Thanks
 
Upvote 0

mandargholap

Member
Licensed User
Longtime User
Thanks Mahares,

There was some issue wih emulator date time format. The issue is being resolved.

Thanks for the help.
 
Upvote 0
Top