Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Days in a month


Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2005, 02:52 AM
samsoon82 samsoon82 is offline
Freshman
 
Join Date: Aug 2005
Posts: 37
Default


i wanna ask the DaysInMonth function. Is that the function return the number of days of current month ?

Code:
DaysInMonth = Day(DateSerial(Year_Number, Month_Number + 1, 0))
the Year_number and the Month_number is refer to wat date ?

Last edited by italkid; 09-12-2005 at 03:08 AM. Reason: Please start your own thread if you have a question...
Reply With Quote
  #2  
Old 09-12-2005, 03:11 AM
TeraBlight's Avatar
TeraBlight TeraBlight is offline
Captain Convoluted

* Expert *
 
Join Date: Jun 2005
Posts: 1,918
Default

Yes, that is a good way of doing this.
The values Year_Number and Month_Number are just Year(Now) and Month(Now), respectively.
__________________
"To learn without thinking is to labour in vain" - Confucius
Reply With Quote
  #3  
Old 09-12-2005, 02:45 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

If you would like to get the date of the last day of the month, you can also use the dateadd function (twice) to add 1 month to the first of the current month and then subtract 1 day from that calc.
Code:
Public Function LastOfMonth (ByRef CurrentDate as Date) as Date LastOfMonth = DateAdd ("d", -1, DateAdd("m", 1, cDate(Month(CurrentDate) & "/1/" & Year(CurrentDate)))) End Function Public Function DaysInMonth (ByRef CurrentDate as Date) as Integer DaysInMonth = Day(LastOfMonth(CurrentDate)) End Function
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown

Last edited by loquin; 09-13-2005 at 11:21 AM.
Reply With Quote
  #4  
Old 09-12-2005, 08:56 PM
TeraBlight's Avatar
TeraBlight TeraBlight is offline
Captain Convoluted

* Expert *
 
Join Date: Jun 2005
Posts: 1,918
Default

But...
Code:
DateSerial(Year(CurrentDate), Month(CurrentDate) + 1, 0))
DOES get the date of the last day of the month, and there's let casting involved since date is a numerical type...
__________________
"To learn without thinking is to labour in vain" - Confucius
Reply With Quote
  #5  
Old 09-13-2005, 11:24 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

True, dateserial IS more effecient than dateadd. I guess, more than anything else, I was pointing out an alternative method.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #6  
Old 09-14-2005, 11:34 PM
samsoon82 samsoon82 is offline
Freshman
 
Join Date: Aug 2005
Posts: 37
Default

Quote:
Originally Posted by TeraBlight
But...
Code:
DateSerial(Year(CurrentDate), Month(CurrentDate) + 1, 0))
DOES get the date of the last day of the month, and there's let casting involved since date is a numerical type...

wat is the meaning for
Code:
Month(CurrentDate) + 1
. ?

i just wondering y wanna plus 1 there ?

thanks !
Reply With Quote
  #7  
Old 09-15-2005, 12:24 AM
stevo stevo is offline
Senior Contributor

* Expert *
 
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
Default

if you put zero in the day parameter of the dateserial function then it returns the last day of the previous month(depending what you have in the month parameter) so if you want the current months end of month then you need to add a month.
Reply With Quote
  #8  
Old 09-15-2005, 08:14 PM
samsoon82 samsoon82 is offline
Freshman
 
Join Date: Aug 2005
Posts: 37
Default

Quote:
Originally Posted by stevo
if you put zero in the day parameter of the dateserial function then it returns the last day of the previous month(depending what you have in the month parameter) so if you want the current months end of month then you need to add a month.

thanks a lot ...now i get wat i wan oredi ...thanks to all that reply my post and helped me ...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->