Results 1 to 18 of 18

Thread: First and Last Day Of Month

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    83

    First and Last Day Of Month

    Hi Friends I need to Know the First and Last Day of Month . The PArameter is of Month Code.... i m using Seagate Crystal Report 8. ....

  2. #2
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: First and Last Day Of Month

    Hi there.. I was justing searching the forums to find a way to get the last day in any given month in Crystal Reports.

    Did you ever figure that out?

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Well the first day of the Month should be the first, right ?
    and you could use the following to find the last day of the month:


    VB Code:
    1. Dim dtDate as Date
    2. dtDate = "09/09/2005"
    3.  
    4. DateAdd("m",DateSerial(Year(dtDate), Month(dtDate), 1) - 1
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Here is another LINK that finds the number of days in a month
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: First and Last Day Of Month

    Quote Originally Posted by Mark Gambo
    Here is another LINK that finds the number of days in a month
    I thought they want the formula in the CR not in the VB.

  6. #6
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Quote Originally Posted by shakti5385
    I thought they want the formula in the CR not in the VB.
    Hmmm, maybe so but with the examples I supplied the op should be able to create the CR Formula.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  7. #7
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    But here is the CR Formula:


    VB Code:
    1. DateAdd("m",1,DateSerial(Year({Table1.dtDate}), Month({Table1.dtDate}),1))-1

    @ Shakti - Looks like my code in post #3 except without the Variable.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: First and Last Day Of Month

    @Mark Gambo, if you find the last day of the month that itself will tell you the no of days in that month...lol...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  10. #10
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Quote Originally Posted by ganeshmoorthy
    @Mark Gambo, if you find the last day of the month that itself will tell you the no of days in that month...lol...
    Huh??
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Re: First and Last Day Of Month

    Quote Originally Posted by Mark Gambo
    Huh??
    He was saying that in the VB, DTPicker.Day Return the last day of the month.

  12. #12
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: First and Last Day Of Month

    Quote Originally Posted by shakti5385
    He was saying that in the VB, DTPicker.Day Return the last day of the month.
    If you are referring to Post # 4, I just included it because it was germane to the discussion and some of us don't use the DatePicker Control in their apps. BTW, where in this thread was the DatePicker control discussed?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  13. #13
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Wink Re: First and Last Day Of Month

    I am making the formula in the CR related to it. And I am not discussing here on the VB property like dtpicker, the people here related on the reporting post, let wait for the thread starter reply.
    Dtpicker is not a metter here.

  14. #14
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Arrow Re: First and Last Day Of Month

    Quote Originally Posted by Mark Gambo
    But here is the CR Formula:


    VB Code:
    1. DateAdd("m",1,DateSerial(Year({Table1.dtDate}), Month({Table1.dtDate}),1))-1

    @ Shakti - Looks like my code in post #3 except without the Variable.
    This is also not giving the result, In CR it dispalying the Date only not the last day of Month.

  15. #15
    New Member
    Join Date
    Jul 2009
    Posts
    2

    Re: First and Last Day Of Month

    'try this......... 2 DTpicker set to First and Last day of the month



    Private Sub Form_Load()
    DTPicker1.Value = DateAdd("d", -(Day(Date) - 1), Date)
    DTPicker2.Value = DateAdd("d", (getNumberOfDays - 1), DTPicker1.Value)
    End Sub
    'Get the number of days each month is having
    Public Function getNumberOfDays() As Integer
    Select Case DateTime.Month(Date)
    Case 1, 3, 5, 7, 8, 10, 12
    getNumberOfDays = 31
    Case 4, 6, 9, 11
    getNumberOfDays = 30
    Case 2
    'logic for checking leap years
    If (Year(Date) Mod 4) = 0 Then
    If (Year(Date) Mod 100) = 0 Then
    If (Year(Date) Mod 400) = 0 Then
    getNumberOfDays = 29
    Else
    getNumberOfDays = 28
    End If
    Else
    getNumberOfDays = 29
    End If
    Else
    getNumberOfDays = 28
    End If
    End Select
    End Function

  16. #16
    New Member
    Join Date
    Jul 2009
    Posts
    2

    Re: First and Last Day Of Month

    'try this......... 2 DTpicker set to First and Last day of the month



    Private Sub Form_Load()
    DTPicker1.Value = DateAdd("d", -(Day(Date) - 1), Date)
    DTPicker2.Value = DateAdd("d", (getNumberOfDays - 1), DTPicker1.Value)
    End Sub

    'Get the number of days each month is having
    Public Function getNumberOfDays() As Integer
    Select Case DateTime.Month(Date)
    Case 1, 3, 5, 7, 8, 10, 12
    getNumberOfDays = 31
    Case 4, 6, 9, 11
    getNumberOfDays = 30
    Case 2
    'logic for checking leap years
    If (Year(Date) Mod 4) = 0 Then
    If (Year(Date) Mod 100) = 0 Then
    If (Year(Date) Mod 400) = 0 Then
    getNumberOfDays = 29
    Else
    getNumberOfDays = 28
    End If
    Else
    getNumberOfDays = 29
    End If
    Else
    getNumberOfDays = 28
    End If
    End Select
    End Function

  17. #17
    Addicted Member
    Join Date
    Nov 2010
    Posts
    161

    Re: First and Last Day Of Month

    Quote Originally Posted by Mark Gambo View Post
    Well the first day of the Month should be the first, right ?
    and you could use the following to find the last day of the month:


    VB Code:
    1. Dim dtDate as Date
    2. dtDate = "09/09/2005"
    3.  
    4. DateAdd("m",DateSerial(Year(dtDate), Month(dtDate), 1) - 1
    I know this is an old thread but there's a bug in the above code, there are 4 opening parenthesis but only 3 closing ones. I'm trying to understand how it works but with the bug/missing parenthesis it's hard to understand.

  18. #18
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: First and Last Day Of Month

    Yeah it looks like something went wrong there.

    The idea is that you use DateSerial to get 1st day of the month:-
    VB Code:
    1. DateSerial(Year(dtDate), Month(dtDate), 1)

    To get the last day of the month you add a month to the first day then subtract 1 day which gives you
    VB Code:
    1. DateAdd("d", -1, DateAdd("M", 1, DateSerial(Year(dtDate), Month(dtDate), 1)))
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width