Date.subtract function
#1
Posted 24 July 2012 - 12:38 PM
#2
Posted 24 July 2012 - 01:13 PM
#3
Posted 24 July 2012 - 01:13 PM
Seems like it would do what you want, if you use the code a lot you may benefit from wrapping it as a static method
//C# public static int MinutesDifference(DateTime lastGPSInfo){ return (DateTime.Now.Subtract(lastGPSInfo).Ticks/TimeSpan.TicksPerMinute); } //VB.Net - My VB is very rusty example is from memory so may not work at all ;-) Public Shared Function MinutesDifference(ByVal lastGPSInfo As DateTime) As Int Return (DateTime.Now.Subtract(lastGPSInfo).Ticks/TimeSpan.TicksPerMinute) End Function
Nak.
#4
Posted 24 July 2012 - 01:26 PM
What is the issue with your work around?
Seems like it would do what you want, if you use the code a lot you may benefit from wrapping it as a static method
//C# public static int MinutesDifference(DateTime lastGPSInfo){ return (DateTime.Now.Subtract(lastGPSInfo).Ticks/TimeSpan.TicksPerMinute); } //VB.Net - My VB is very rusty example is from memory so may not work at all ;-) Public Shared Function MinutesDifference(ByVal lastGPSInfo As DateTime) As Int Return (DateTime.Now.Subtract(lastGPSInfo).Ticks/TimeSpan.TicksPerMinute) End Function
Nak.
Hi Guys,
There is nothing wrong with my workaround, except that it needs more code to do as compare to DateDiff method. As you know code size for our little Netduino is precious.
#5
Posted 24 July 2012 - 01:38 PM
The memory overhead of your work-around has virtually no impact on memory usage as long as you define it in one place only as suggested by nakchak or implement it as an extension method of the Timespan class.There is nothing wrong with my workaround, except that it needs more code to do as compare to DateDiff method. As you know code size for our little Netduino is precious.
Personally, I find the latter to be slightly more elegant ;-)
#6
Posted 24 July 2012 - 01:58 PM
#7
Posted 24 July 2012 - 02:06 PM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#8
Posted 24 July 2012 - 02:55 PM
public static int Totalminutes(this Timespan ts) { return 3577444; }
#9
Posted 24 July 2012 - 03:13 PM
I honestly have no idea what you mean. If I add that code to an empty project it will give errors. 'this' is a keyword, is that intended? Am I on the border of learning something new here?Rather outside a class, in C# you would write something like this:
public int Totalminutes(Timespan this) { return 3577444; }I'm pretty sure you can do this in VB too but I don't know the syntax.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#10
Posted 24 July 2012 - 03:21 PM
#11
Posted 24 July 2012 - 04:01 PM
#12
Posted 24 July 2012 - 04:11 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users