[RexxLA] How to just get back the number of days component using datetime class?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[RexxLA] How to just get back the number of days component using datetime class?

Michael Lueck
Greetings RexxLS'ers,

Using the ooRexx datetime class,

StaticDateObj = .datetime~new('2018', '02', '05')
TodayDateObj = .datetime~new()

say 'Days since Feb 5: ' TodayDateObj - StaticDateObj

Output: Days since Feb 5:  64.07:24:14.963379

How to get it just to display the 64 days portion of the number?

Seems like the result of the subtraction ends up as a resulting temporary datetime object I would need to be able to act upon specifying days only output format, correct?

I am thankful,

--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/
_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

Kees Wiegel
​Hi Michael,

Try this:​

StaticDateObj =.datetime~new('2018','02','05')
TodayDateObj  =.datetime~new()
TimePast=TodayDateObj-StaticDateObj
Parse var TimePast DaysGone'.'.
Say 'Days since Feb 5:' DaysGone

You're welcome!

Kees Wiegel.

Sent with Mailtrack

2018-04-10 13:35 GMT+02:00 Michael Lueck <[hidden email]>:
Greetings RexxLS'ers,

Using the ooRexx datetime class,

StaticDateObj = .datetime~new('2018', '02', '05')
TodayDateObj = .datetime~new()

say 'Days since Feb 5: ' TodayDateObj - StaticDateObj

Output: Days since Feb 5:  64.07:24:14.963379

How to get it just to display the 64 days portion of the number?

Seems like the result of the subtraction ends up as a resulting temporary datetime object I would need to be able to act upon specifying days only output format, correct?

I am thankful,

--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/
_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members


_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

ErichSt
In reply to this post by Michael Lueck
Seems like the result of the subtraction ends up as a resulting temporary datetime object
Michael, subtracting two DateTime instances gives a TimeSpan instance.
To retrieve the whole days from a TimeSpan, use the days() method

say (.DateTime~new - .DateTime~new("2018", "02", "05"))~days


_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

Michael Lueck
In reply to this post by Kees Wiegel
Greetings Kees,

Kees Wiegel wrote:

>
> Try this:​
>
> StaticDateObj =.datetime~new('2018','02','05')
> TodayDateObj  =.datetime~new()
> TimePast=TodayDateObj-StaticDateObj
> Parse var TimePast DaysGone'.'.
> Say 'Days since Feb 5:' DaysGone
>
> You're welcome!


That solution works.

I suspect TimePast also becomes a datetime object, and that the parse var results in conversion back to plain string object. That is what I was seeking.

I am thankful,

--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/
_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

Michael Lueck
In reply to this post by ErichSt
Greetings Erich,


Erich Steinböck wrote:
> To retrieve the whole days from a TimeSpan, use the days() method
>
> say (.DateTime~new - .DateTime~new("2018", "02", "05"))~days


And that was the sort of oo style solution I was seeking! :-)

I could not find "days" as a method of the datetime class. I only say "day" available. Where does that come from within the class library?

I am thankful,

--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/
_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

ErichSt
I could not find "days" as a method of the datetime class
Michael, DateTime does not have a days() method.
Subtracting two DateTime instances returns a TimeSpan instance (which does have a days() method)

If you'd like to know what class a given instance belongs to, use the class() method, e.g.
say (.DateTime~new - .DateTime~new("2018", "02", "05"))~class  -->  The TimeSpan class

_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members
Reply | Threaded
Open this post in threaded view
|

Re: [RexxLA] How to just get back the number of days component using datetime class?

Michael Lueck
Greetings Erich,

Erich Steinböck wrote:
>     I could not find "days" as a method of the datetime class
>
> Michael, DateTimedoes not have a days() method.
> Subtracting two DateTimeinstances returns a TimeSpan instance (which /does/ have a days()method)
>
> If you'd like to know what class a given instance belongs to, use the class()method, e.g.
> say (.DateTime~new - .DateTime~new("2018", "02", "05"))~class  --> The TimeSpan class


aaahhhh.... TimeSpan class!!! An entire associated class I had not realized was included!

I am thankful,

--
Michael Lueck
Lueck Data Systems
http://www.lueckdatasystems.com/
_______________________________________________
rexxla-members mailing list -- mailto:[hidden email]
http://rexxla.org/mailman/listinfo/rexxla-members