10 Replies - 722 Views - Last Post: 05 October 2012 - 07:54 AM Rate Topic: -----

#1 JackobzKoome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-September 12

How to tell date position in a year

Posted 04 October 2012 - 04:17 AM

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
Is This A Good Question/Topic? 0
  • +

Replies To: How to tell date position in a year

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

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

Was This Post Helpful? 1
  • +
  • -

#3 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

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

Was This Post Helpful? 1
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

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.
Was This Post Helpful? 0
  • +
  • -

#5 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

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.
Was This Post Helpful? 0
  • +
  • -

#6 JackobzKoome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-September 12

Re: How to tell date position in a year

Posted 05 October 2012 - 12:22 AM

View Postmaj3091, 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
Was This Post Helpful? 0
  • +
  • -

#7 JackobzKoome  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 21-September 12

Re: How to tell date position in a year

Posted 05 October 2012 - 12:30 AM

View Postkai_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 :)

Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

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.
Was This Post Helpful? 0
  • +
  • -

#9 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: How to tell date position in a year

Posted 05 October 2012 - 06:43 AM

View PostAdamSpeight2008, on 05 October 2012 - 02:29 PM, said:

Still don't know whether the OP is using vb.net or not.


I'd guess VB6 as he took the VB6 function. :)
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

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.
Was This Post Helpful? 0
  • +
  • -

#11 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1