Hi can anyone help me to know how to tell the position of a date in a year, for example 1st january will be 1 out of 365
and 1st february will be 32 out of 365
How to tell date position in a year
Page 1 of 110 Replies - 352 Views - Last Post: 05 October 2012 - 07:54 AM
Replies To: How to tell date position in a year
#2
Re: How to tell date position in a year
Posted 04 October 2012 - 05:29 AM
HERE IS A ROUGH CALCULATION,,,BUT PROVIDE YOU YOUR DESIRED RESULT
FOR THIS I HAVE CREATED A FORM, A TEXTBOX (enter valid value between 1 to 31), 12 RADIOBUTTONS (ACT AS JANUARY TO DECEMBER), AND A BUTTON (SUBMIT)
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlDataReader
Imports System.IO
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = Val(TextBox1.Text) And RadioButton1.Checked = True Then
MessageBox.Show(Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton2.Checked = True Then
MessageBox.Show(31 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton3.Checked = True Then
MessageBox.Show(59 + Val(TextBox1.Text))
' 59 becoz (31(total days in jan) + (total days in feb)28)
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton4.Checked = True Then
MessageBox.Show(90 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton5.Checked = True Then
MessageBox.Show(120 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton6.Checked = True Then
MessageBox.Show(151 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton7.Checked = True Then
MessageBox.Show(181 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton8.Checked = True Then
MessageBox.Show(212 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton9.Checked = True Then
MessageBox.Show(242 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton10.Checked = True Then
MessageBox.Show(273 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton11.Checked = True Then
MessageBox.Show(303 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton12.Checked = True Then
MessageBox.Show(334 + Val(TextBox1.Text))
End If
End Sub
End Class
enjoy
This post has been edited by kai_itz me: 04 October 2012 - 05:32 AM
#3
Re: How to tell date position in a year
Posted 04 October 2012 - 05:47 AM
If you're using VB6, you could use a simple function as follows:
Private Function fintGetDayOfYear() As Integer
Dim strStartOfYear as string
' Create a string to represent first day of year
strStartOfYear = "01/01/" & CStr(Year(Date))
' Calculate the difference in days, between todays date and start of year, then add one to include current day
fintGetDayOfYear = DateDiff("d", strStartOfYear, Date) + 1
End Function
This post has been edited by maj3091: 04 October 2012 - 05:47 AM
#4
Re: How to tell date position in a year
Posted 04 October 2012 - 06:06 AM
Dim yearday = Date.Parse("04/10/2012").DayOfYear
Is the .net framework helpful.
#5
Re: How to tell date position in a year
Posted 04 October 2012 - 07:53 AM
.net has some great functions, but as the OP dropped in the VB6 forum, I went the old fashioned route. 
Maybe the OP could confirm which VB he is using.
Maybe the OP could confirm which VB he is using.
#6
Re: How to tell date position in a year
Posted 05 October 2012 - 12:22 AM
maj3091, on 04 October 2012 - 05:47 AM, said:
If you're using VB6, you could use a simple function as follows:
Private Function fintGetDayOfYear() As Integer
Dim strStartOfYear as string
' Create a string to represent first day of year
strStartOfYear = "01/01/" & CStr(Year(Date))
' Calculate the difference in days, between todays date and start of year, then add one to include current day
fintGetDayOfYear = DateDiff("d", strStartOfYear, Date) + 1
End Function
Thanks this worked for me
#7
Re: How to tell date position in a year
Posted 05 October 2012 - 12:30 AM
kai_itz me, on 04 October 2012 - 05:29 AM, said:
HERE IS A ROUGH CALCULATION,,,BUT PROVIDE YOU YOUR DESIRED RESULT
FOR THIS I HAVE CREATED A FORM, A TEXTBOX (enter valid value between 1 to 31), 12 RADIOBUTTONS (ACT AS JANUARY TO DECEMBER), AND A BUTTON (SUBMIT)
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlDataReader
Imports System.IO
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = Val(TextBox1.Text) And RadioButton1.Checked = True Then
MessageBox.Show(Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton2.Checked = True Then
MessageBox.Show(31 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton3.Checked = True Then
MessageBox.Show(59 + Val(TextBox1.Text))
' 59 becoz (31(total days in jan) + (total days in feb)28)
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton4.Checked = True Then
MessageBox.Show(90 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton5.Checked = True Then
MessageBox.Show(120 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton6.Checked = True Then
MessageBox.Show(151 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton7.Checked = True Then
MessageBox.Show(181 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton8.Checked = True Then
MessageBox.Show(212 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton9.Checked = True Then
MessageBox.Show(242 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton10.Checked = True Then
MessageBox.Show(273 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton11.Checked = True Then
MessageBox.Show(303 + Val(TextBox1.Text))
End If
If TextBox1.Text = Val(TextBox1.Text) And RadioButton12.Checked = True Then
MessageBox.Show(334 + Val(TextBox1.Text))
End If
End Sub
End Class
enjoy
#8
Re: How to tell date position in a year
Posted 05 October 2012 - 06:29 AM
Still don't know whether the OP is using vb.net or not.
#9
Re: How to tell date position in a year
Posted 05 October 2012 - 06:43 AM
#10
Re: How to tell date position in a year
Posted 05 October 2012 - 07:19 AM
And the vb.net one above my previous reply.
#11
Re: How to tell date position in a year
Posted 05 October 2012 - 07:54 AM
Yeah, fair point, but he didn't comment on that one as to whether he used it or it worked....guess we'll never know.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|