Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.

Nth Day of the Month (& numerical Day of the week)

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 10:43 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 160
Awards Showcase
Beta Tester 
Total Awards: 1
Default Nth Day of the Month (& numerical Day of the week)

I needed these, so I guess that you might too..

Use the calendar to choose a weekday (& also to check the answers). Choose the nth occurrence for that day in the month & click GO.

The way the form is set up it gives you little practical utility, but if you need a way to set up a year's calendar (e.g. with holidays on the 1st Monday of August) or a recurrent meeting (e.g. on the 3rd Thursday of the month) then you might just find these helpful.

Erel, I can't see the DayNumber() within the native functions, although "DayName" is there.
Attached Files
File Type: sbp NthDay.sbp (2.0 KB, 66 views)
Reply With Quote
  #2 (permalink)  
Old 02-18-2008, 03:29 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

You could use the following sub to get the number of the day (1 - Sunday...):
Code:
Sub DayNumber(ticks)
    
Return (Int(ticks/cTicksPerDay)) Mod 7 + 2
End Sub
Reply With Quote
  #3 (permalink)  
Old 02-18-2008, 09:04 PM
LineCutter's Avatar
Senior Member
 
Join Date: May 2007
Location: Daarsit
Posts: 160
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Amazing how you always have a better answer Consider my version to be a demonstration of how to do the same job in a more generic (complicated) fashion.

Oh, for the record, the nthDay sub needs 0=Sunday, 1=Monday etc.
Reply With Quote
  #4 (permalink)  
Old 06-19-2009, 02:15 PM
Knows the basics
 
Join Date: May 2007
Posts: 78
Awards Showcase
Beta Tester 
Total Awards: 1
Default Week Number

Hi
Is there an easier way to calculate the:
(1) Week number of the Year?
(2) number of days between two given dates?

Thanks!
Reply With Quote
  #5 (permalink)  
Old 06-20-2009, 10:13 AM
Knows the basics
 
Join Date: May 2007
Posts: 78
Awards Showcase
Beta Tester 
Total Awards: 1
Default Week Number

Hi All,
I did a search and found some codes and converted them to Basic4PPC format. It's based on the European/ISO standard... Though below sub is to get the weeknum... variable 'd' is also the day of the week which of course is redundant since Basic4PPC already has similar function.

Hope the 'WeekNum' sub helps...

Rgds
WZSun

================================


Sub WeekNumber(yr,mh,dy)
'http://www.tondering.dk/claus/cal/node8.html
If mh < 3 Then 'for dates in months of Jan/Feb
a = yr - 1
b = Int(a/4) - Int(a/100) + Int(a/400)
c = Int((a-1)/4) - Int((a-1)/100) + Int((a-1)/400)
s = b-c
e = 0
f = dy - 1 + 31 * (mh-1)
Else ' for dates in March - December
a = yr
b = Int(a/4) - Int(a/100) + Int(a/400)
c = Int((a-1)/4) - Int((a-1)/100) + Int((a-1)/400)
s = b-c
e = s + 1
f = dy + ((153 * (mh-3)+2)/5) + 58 + s
End If
g = Int((a+b)) Mod 7
If g = 0 Then g = 7
d = Int((f + g - e)) Mod 7
If d = 0 Then d = 7
n = f + 3-d

If n < 0 Then
i = 53 - Int((g-s)/5)
Else If n > 364 + s Then
i = 1
Else
i = Int(n/7)+1
End If
'Note: d = day of the week '0=monday, 1 - tuesday
Return i
End Sub
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic4ppc V6.30 beta will be released next week Erel Announcements 19 09-17-2008 09:36 PM
calendar week (European) stbi Code Samples & Tips 5 07-03-2007 10:16 PM


All times are GMT. The time now is 03:56 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0