I have two dates. I need to figure out how many days and months are between the two. What is the best way to do it?

1 |

8/29/2006 10:27:41 PM

The number of days can be calculated with the PB function RelativeDate. The number of months can be calculated with the PFC function of_RelativeMonth (pfc_n_cst_datetime). Brad "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >I have two dates. I need to figure out how many days and months are > between the two. What is the best way to do it?

0 |

8/30/2006 2:09:12 AM

For months, it's easy: number of years = Year(Date2) = Year(Date1) number of months = Month(Date2) - Month(Date1) + (number of years * 12) For days, it's more difficult. If the day of Date2 > day of Date1, you can just use: number of days = Day(Date2) - Day(Date1) For example, 6/17/06 as the first date and 8/28/06 as the second date, you would get 2 months and 11 days. But, when you have 6/28/06 and 8/17/06, how do you want to figure out the number of days? You could do: (last day of the month of the first date - day of the month of the first date) + day of the month of the second date So, in our example you'd get 1 month and 19 days. if number of days < 0 then number of months -= 1 number of days = (last day of month - Day (Date1)) + Day (Date2) end For the last day of month, you would need to take into account which month and for February account for leap years. If you wanted to use the n_cst_datetime object in the PFC, you have the functions of_LastDayOfMonth() and of_MonthsAfter() to do some of the calculations above. HTH, steve [TeamSybase] "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >I have two dates. I need to figure out how many days and months are > between the two. What is the best way to do it?

0 |

8/30/2006 2:28:33 AM

Both RelativeDate and of_RelativeMonth will give you a new date/month an offset number of days/months ahead/behind the current date. It won't tell you how many months/days are between 2 date values. steve [TeamSybase] "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message news:44f4f0ad@forums-2-dub... > The number of days can be calculated with the PB function RelativeDate. > The number of months can be calculated with the PFC function > of_RelativeMonth (pfc_n_cst_datetime). > > Brad > > "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message > news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>I have two dates. I need to figure out how many days and months are >> between the two. What is the best way to do it? > >

0 |

8/30/2006 2:32:36 AM

If you are using ASA you can use the date functions of the database also, like DATEDIFF. "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >I have two dates. I need to figure out how many days and months are > between the two. What is the best way to do it?

0 |

8/30/2006 7:02:27 AM

I ended up using your suggestion and had to create a global function to calculate number of days between two dates to be called from the datawindow. You would think that this would be easier. Thanks for your help! Roman On 29 Aug 2006 19:28:33 -0700, "Steve Katz [TeamSybase]" <steve.katz@teamsybase.com> wrote: >For months, it's easy: > >number of years = Year(Date2) = Year(Date1) >number of months = Month(Date2) - Month(Date1) + (number of years * 12) > >For days, it's more difficult. If the day of Date2 > day of Date1, you can >just use: >number of days = Day(Date2) - Day(Date1) > >For example, 6/17/06 as the first date and 8/28/06 as the second date, you >would get >2 months and 11 days. > >But, when you have 6/28/06 and 8/17/06, how do you want to figure out the >number of days? You could do: > >(last day of the month of the first date - day of the month of the first >date) + day of the month of the second date > >So, in our example you'd get 1 month and 19 days. > >if number of days < 0 then > number of months -= 1 > number of days = (last day of month - Day (Date1)) + Day (Date2) >end > >For the last day of month, you would need to take into account which month >and for February account for leap years. > >If you wanted to use the n_cst_datetime object in the PFC, you have the >functions of_LastDayOfMonth() and of_MonthsAfter() to do some of the >calculations above. > >HTH, > >steve >[TeamSybase] > >"Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message >news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>I have two dates. I need to figure out how many days and months are >> between the two. What is the best way to do it? >

0 |

8/30/2006 5:07:36 PM

What on earth was I thinking? "Steve Katz [TeamSybase]" <steve.katz@teamsybase.com> wrote in message news:44f4f8c4$1@forums-1-dub... > Both RelativeDate and of_RelativeMonth will give you a new date/month an > offset number of days/months ahead/behind the current date. It won't tell > you how many months/days are between 2 date values. > > steve > [TeamSybase] > > "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message > news:44f4f0ad@forums-2-dub... >> The number of days can be calculated with the PB function RelativeDate. >> The number of months can be calculated with the PFC function >> of_RelativeMonth (pfc_n_cst_datetime). >> >> Brad >> >> "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message >> news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>>I have two dates. I need to figure out how many days and months are >>> between the two. What is the best way to do it? >> >> > >

0 |

8/30/2006 5:52:03 PM

You were probably under the spell of the same evil sorceror that caused me to give the reply I did in this thread: http://groups.google.com/group/sybase.public.powerbuilder.general/browse_frm/thread/4586a0a0b57667c6/7839346c3560729b?lnk=st&q=ken+balakrishnan+powerbuilder+relativedate+daysafter&rnum=1#7839346c3560729b "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message news:44f5d043@forums-1-dub... > What on earth was I thinking? > > > "Steve Katz [TeamSybase]" <steve.katz@teamsybase.com> wrote in message > news:44f4f8c4$1@forums-1-dub... >> Both RelativeDate and of_RelativeMonth will give you a new date/month an >> offset number of days/months ahead/behind the current date. It won't >> tell you how many months/days are between 2 date values. >> >> steve >> [TeamSybase] >> >> "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message >> news:44f4f0ad@forums-2-dub... >>> The number of days can be calculated with the PB function RelativeDate. >>> The number of months can be calculated with the PFC function >>> of_RelativeMonth (pfc_n_cst_datetime). >>> >>> Brad >>> >>> "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message >>> news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>>>I have two dates. I need to figure out how many days and months are >>>> between the two. What is the best way to do it? >>> >>> >> >> > >

0 |

8/30/2006 9:53:27 PM

LOL. It's good to know I'm not alone... "Ken Balakrishnan" <kNOeSPAMn@cps92.com> wrote in message news:44f60638@forums-2-dub... > You were probably under the spell of the same evil sorceror that caused me > to give the reply I did in this thread: > > http://groups.google.com/group/sybase.public.powerbuilder.general/browse_frm/thread/4586a0a0b57667c6/7839346c3560729b?lnk=st&q=ken+balakrishnan+powerbuilder+relativedate+daysafter&rnum=1#7839346c3560729b > > > > "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message > news:44f5d043@forums-1-dub... >> What on earth was I thinking? >> >> >> "Steve Katz [TeamSybase]" <steve.katz@teamsybase.com> wrote in message >> news:44f4f8c4$1@forums-1-dub... >>> Both RelativeDate and of_RelativeMonth will give you a new date/month an >>> offset number of days/months ahead/behind the current date. It won't >>> tell you how many months/days are between 2 date values. >>> >>> steve >>> [TeamSybase] >>> >>> "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message >>> news:44f4f0ad@forums-2-dub... >>>> The number of days can be calculated with the PB function RelativeDate. >>>> The number of months can be calculated with the PFC function >>>> of_RelativeMonth (pfc_n_cst_datetime). >>>> >>>> Brad >>>> >>>> "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message >>>> news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>>>>I have two dates. I need to figure out how many days and months are >>>>> between the two. What is the best way to do it? >>>> >>>> >>> >>> >> >> > >

0 |

8/30/2006 11:04:47 PM

Earth? Sounds like you were somewhere else in the galaxy....or universe. S'ok.....been there, done that, too. The penalty, btw, is one week without being allowed to sign with [TeamSybase] in our name.<g> steve [TeamSybase] "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message news:44f5d043@forums-1-dub... > What on earth was I thinking? > > > "Steve Katz [TeamSybase]" <steve.katz@teamsybase.com> wrote in message > news:44f4f8c4$1@forums-1-dub... >> Both RelativeDate and of_RelativeMonth will give you a new date/month an >> offset number of days/months ahead/behind the current date. It won't >> tell you how many months/days are between 2 date values. >> >> steve >> [TeamSybase] >> >> "Brad Wery [TeamSybase]" <bradweryatagricoreunited.com> wrote in message >> news:44f4f0ad@forums-2-dub... >>> The number of days can be calculated with the PB function RelativeDate. >>> The number of months can be calculated with the PFC function >>> of_RelativeMonth (pfc_n_cst_datetime). >>> >>> Brad >>> >>> "Roman Kastin" <roman DOT kastin AT gsa.gov> wrote in message >>> news:51f9f2p6jcnd6kl6qhvgiieom496tiec69@4ax.com... >>>>I have two dates. I need to figure out how many days and months are >>>> between the two. What is the best way to do it? >>> >>> >> >> > >

0 |

8/31/2006 4:32:30 AM