Hello Guys,
I was working on a project of a hotel management system. I had to calculate the day between two given dates by DateTimePicker in vb.NET.
I named the DateTimePicker as "DTPcheckin" for the day when customer checks into the hotel and
"DTPcheckout" for the date of checkout.
To calculate the date and to facilitate myself for the later calculation and SQL comparisons I converted the date to the NUMBER OF DAYS FROM THE BEGINNING OF THE CALENDER .
LIKE "20 MARCH 2013" == 735328. that is 735328 days passed from date 01/01/0001.
U can use this anywhere you want. here is the code------
Dim checkin_day As Integer
Dim checkout_day As Integer
Dim checkin_month As Integer
Dim checkout_month As Integer
Dim checkin_y As Integer
Dim checkout_y As Integer
Dim staying As Integer
Dim mdcin As Integer
Dim mdcout As Integer
Dim daycin As Integer
Dim daycout As Integer
Private Sub calday()
checkin_day = CInt(DTPcheckin.Value.Day)
checkout_day = CInt(DTPcheckout.Value.Day)
checkin_month = CInt(DTPcheckin.Value.Month)
checkout_month = CInt(DTPcheckout.Value.Month)
checkin_y = CInt(DTPcheckin.Value.Year)
checkout_y = CInt(DTPcheckout.Value.Year)
mdcin = mdcount(checkin_month)
mdcout = mdcount(checkout_month)
daycin = checkin_y * 365 + mdcin + checkin_day
Dim temp2 As Integer = checkin_y - 1
temp2 = temp2 / 4
daycin = daycin + temp2
If (checkin_y Mod 400 = 0 Or (checkin_y Mod 100 <> 0 And checkin_y Mod 4 = 0)) And checkin_month > 2 Then
daycin = daycin + 1
End If
daycout = checkout_y * 365 + mdcout + checkout_day
Dim temp As Integer = checkout_y - 1
temp = temp / 4
daycout = daycout + temp
If (checkout_y Mod 400 = 0 Or (checkout_y Mod 100 <> 0 And checkout_y Mod 4 = 0)) And checkout_month > 2 Then
daycout = daycout + 1
End If
//duration is calculate by subtracting the daycin from daycout
duration = daycout - daycin
End Sub
//the mdcount function is
//this mdcount function calculate the number of days from 1st jan to the given month
Public Function mdcount(ByVal n As Integer) As Integer
Dim md As Integer
If n = 1 Then
md = 0
ElseIf n = 2 Then
md = 31
ElseIf n = 3 Then
md = 59
ElseIf n = 4 Then
md = 90
ElseIf n = 5 Then
md = 120
ElseIf n = 6 Then
md = 151
ElseIf n = 7 Then
md = 181
ElseIf n = 8 Then
md = 212
ElseIf n = 9 Then
md = 243
ElseIf n = 10 Then
md = 273
ElseIf n = 11 Then
md = 304
ElseIf n = 12 Then
md = 334
End If
Return md
End Function
The way of describing about Technology is fine.Im really happy to read this.please share more like this.
ReplyDeleteDOT NET Training in Chennai
DOT NET Training Institute in Chennai
Dot Net Training in Anna Nagar
Html5 Training in Chennai
Html5 Course
QTP Training in Chennai
SAS Training in Chennai
DOT NET Training in Chennai
IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes. IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble.Final Year Projects for CSE
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining .
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
The Angular Training covers a wide range of topics including Angular Directives, Angular Services, and Angular programmability.Angular Training
Awesome post with lots of data and I have bookmarked this page for my reference. Share more ideas frequently.
ReplyDeleteUiPath Training in Chennai
Blue Prism Training in Chennai
Blue Prism Training Institute in Chennai
RPA Training in Chennai
RPA course in Chennai
RPA Training Institute in Chennai
RPA Training in Tambaram
Blue Prism Training Chennai
Thanks for this wonderful blog it is really informative to all.
ReplyDeleteTOEFL Coaching in Chennai
TOEFL Training in Chennai
Spoken English in Chennai
french courses in chennai
pearson vue test center in chennai
German Classes in Chennai
TOEFL Coaching in VelaChery
TOEFL Coaching in Tambaram
IELTS Coaching in anna nagar
best spoken english institute in anna nagar
Nice post...! I really happy to visit your post and do a post like this more with more info. well done, keep it up the great work!!!
ReplyDeleteSpark Training in Chennai
Spark Training Academy Chennai
Linux Training in Chennai
Oracle Training in Chennai
Social Media Marketing Courses in Chennai
Power BI Training in Chennai
Tableau Training in Chennai
Excel Training in Chennai
Oracle DBA Training in Chennai
Spark Training in Valachery
One of the best blogs that I have read till now. Thanks for your contribution to sharing such useful information. Waiting for your further updates.
ReplyDeleteSpoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
Thanks a lot for sharing such a good source with all, i appreciate your efforts taken for the same. I found this worth sharing and must share this with all.
ReplyDeleteDot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery
awesome article,the content has very informative ideas, waiting for the next update...
ReplyDeleteStudy Abroad Consultants in Kerala
study abroad consultants in thrissur
Study Abroad Consultants in Calicut
abroad job consultancy in coimbatore
Abroad Education Consultants in Coimbatore
europe job consultancy in coimbatore
study abroad
study in poland
study in europe
free masters in germany
This comment has been removed by the author.
ReplyDeleteGreat idea! Kind sharing this article. I got some useful information from your blog.
ReplyDeletehow to write seo content
english in german
salesforce tips
software testing material
ethical hacking books
tableau interview questions and answers
tableau admin interview questions
Great post! I really appreciate you and I like to more unique content about this title and keep updating here...
ReplyDeleteInformatica Training in Bangalore
Informatica Training in Chennai
Informatica MDM Training in Chennai
Informatica Course in Chennai