HELP VB.NET DATE DIFFERENCE CODE

I intend to get the difference of days between two given dates unfortunately all methods have used are firing an exception especially on type casting a string to date so far have used *DateTime.parse() and DateDiff() anyone any idea* -- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com

Try this Dim dpReturn As Date = CType(Me.dpReturnDate.Value, Date) Dim dpDue As Date = dpDueDate.Value Dim dpReturn As Date = dpReturnDate.Value Dim dpDue As Date = CType(Me.dpReturnDate.Value, Date) Dim MyDifference As TimeSpan MyDifference = dpReturn.Subtract(dpDue) ' find the number of days apart On Thu, Aug 25, 2011 at 1:06 PM, MICHAEL AKUNGA <michaelakunga@gmail.com>wrote:
I intend to get the difference of days between two given dates unfortunately all methods have used are firing an exception especially on type casting a string to date so far have used *DateTime.parse() and DateDiff() anyone any idea*
-- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Justus +254 724 46 55 99

Justus thank you for your response but I was a bit mixed with you code there are ambiguous types this is what I made it. Dim dpReturn As Date = CType(Me.dpReturnDate.Value, Date) Dim dpDue As Date = CType(Me.dpduedate.Value, Date) Dim MyDifference As TimeSpan MyDifference = dpReturn.Subtract(dpDue) ' find the number of days apart TextBox1.Text = CInt(MyDifference) now watch this CInt(MyDifference) can not be type casted. ahaaaaa men this thing is holding me up my previous code in the project looks like this stDate = CDate(.Item(3).ToString) ' this is a date stored in a database being converted to date dtDate = DateTime.Parse(stDate, Globalization.CultureInfo.CreateSpecificCulture("en-CA")) amount = DateDiff(DateInterval.Day, Now, dtDate) * fratepday ANY SUPPORT HIGHLY APPRECIATED On Thu, Aug 25, 2011 at 1:32 PM, justus <mutahijustus@gmail.com> wrote:
Try this
Dim dpReturn As Date = CType(Me.dpReturnDate.Value, Date) Dim dpDue As Date = dpDueDate.Value Dim dpReturn As Date = dpReturnDate.Value Dim dpDue As Date = CType(Me.dpReturnDate.Value, Date) Dim MyDifference As TimeSpan MyDifference = dpReturn.Subtract(dpDue) ' find the number of days apart
On Thu, Aug 25, 2011 at 1:06 PM, MICHAEL AKUNGA <michaelakunga@gmail.com>wrote:
I intend to get the difference of days between two given dates unfortunately all methods have used are firing an exception especially on type casting a string to date so far have used *DateTime.parse() and DateDiff() anyone any idea*
-- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Justus +254 724 46 55 99
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com

I don't understand the bit below - you seem to be doing a lot of unnecessary calculations and conversions
stDate = CDate(.Item(3).ToString) ' this is a date stored in a database being converted to date dtDate = DateTime.Parse(stDate, Globalization.CultureInfo.CreateSpecificCulture("en-CA")) amount = DateDiff(DateInterval.Day, Now, dtDate) * fratepday
Just post the entire code block where you retrieve the data from the database and what calculation you are doing and tutakusaidia. Also, you are using the Timespan wrongly. The documentation is here http://msdn.microsoft.com/en-us/library/system.timespan.aspx The property you want is Days so Textbox.Text = MyDifference.Days

'------------------------------------------------ Dim Difference As Integer = 0 Dim prevdate As Date ' format this date as required Dim nextdate As Date ' format this date as required Difference = DateDiff(DateInterval.Day, prevdate, nextdate) '---------------------------------------------------------------- On 8/25/11, MICHAEL AKUNGA <michaelakunga@gmail.com> wrote:
Justus thank you for your response but I was a bit mixed with you code there are ambiguous types this is what I made it. Dim dpReturn As Date = CType(Me.dpReturnDate.Value, Date) Dim dpDue As Date = CType(Me.dpduedate.Value, Date) Dim MyDifference As TimeSpan MyDifference = dpReturn.Subtract(dpDue) ' find the number of days apart TextBox1.Text = CInt(MyDifference) now watch this CInt(MyDifference) can not be type casted. ahaaaaa men this thing is holding me up my previous code in the project looks like this
stDate = CDate(.Item(3).ToString) ' this is a date stored in a database being converted to date dtDate = DateTime.Parse(stDate, Globalization.CultureInfo.CreateSpecificCulture("en-CA")) amount = DateDiff(DateInterval.Day, Now, dtDate) * fratepday ANY SUPPORT HIGHLY APPRECIATED
On Thu, Aug 25, 2011 at 1:32 PM, justus <mutahijustus@gmail.com> wrote:
Try this
Dim dpReturn As Date = CType(Me.dpReturnDate.Value, Date) Dim dpDue As Date = dpDueDate.Value Dim dpReturn As Date = dpReturnDate.Value Dim dpDue As Date = CType(Me.dpReturnDate.Value, Date) Dim MyDifference As TimeSpan MyDifference = dpReturn.Subtract(dpDue) ' find the number of days apart
On Thu, Aug 25, 2011 at 1:06 PM, MICHAEL AKUNGA <michaelakunga@gmail.com>wrote:
I intend to get the difference of days between two given dates unfortunately all methods have used are firing an exception especially on type casting a string to date so far have used *DateTime.parse() and DateDiff() anyone any idea*
-- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- Justus +254 724 46 55 99
_______________________________________________ Skunkworks mailing list Skunkworks@lists.my.co.ke http://lists.my.co.ke/cgi-bin/mailman/listinfo/skunkworks ------------ Skunkworks Rules http://my.co.ke/phpbb/viewtopic.php?f=24&t=94 ------------ Other services @ http://my.co.ke
-- MICHAEL A. AKUNGA (+254) 0726 174 815 michaelakunga@gmail.com michaelakunga@yahoo.com
participants (4)
-
justus
-
MICHAEL AKUNGA
-
Rad!
-
ukuta ken