Solved

Get year portion of the date

Posted on 2010-09-15
8
353 Views
Last Modified: 2012-05-10
trying to get just the 2 digit year portion o fthe date

Below is my code.

If the month is greater than 9 i need to go to the next year 2011 but i just want the 11 part, if it is less than 9 i want to stay witht eh current fical year.

How can i just get the 2 digit year portion.

Private Function GenerateAutoNumber(ByVal VDATE As Date, ByVal currentNumber As String) As String

        Dim CurrMonth As String = DateTime.Now.ToString("MM")

        Dim Curryear As Double = Convert.ToDouble(currentNumber.Substring(0, 2))

        Dim CurrJulian As String = Convert.ToDouble(currentNumber.Substring(3, currentNumber.Length - 7))

        Dim TodayJulian As String = DateTime.Now.DayOfYear.ToString

        Dim AcnYear As DateTime

        Dim AcnJulian As String

        Dim Incriment As String

     

        If CurrMonth > "9" Then

            AcnYear = DateTime.Now.AddYears(1).ToString

            Response.Write(AcnYear)

            Response.End()

        Else

            Response.Write(DateTime.Now.ToString)

            Response.End()

        End If



        Dim autoNumber As Double = Convert.ToDouble(currentNumber.Substring(7, currentNumber.Length - 7))



        Dim strNumber As String = (autoNumber + 1).ToString("000")



        Return Year(VDATE).ToString.Substring(2) & "-" & VDATE.DayOfYear.ToString("000") & "-" & strNumber.Substring(0, strNumber.Length)

    End Function

Open in new window

0
Comment
Question by:kdeutsch
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33682922
           AcnYear = DateTime.Now.AddYears(1).ToString.SubString(2)
0
 
LVL 1

Expert Comment

by:golftech
ID: 33682960

        Dim d As DateTime
        d = DateTime.Now()
        Dim m As Integer
        m = d.Month
        If m > 9 Then

        Else

        End If
0
 

Author Comment

by:kdeutsch
ID: 33683007
Zhaolai

I have tried that and what i get in a response.write is
15/2011 9:57:41 AM

it looks like it just eliminates the 09 instead of getting the 11 in 2011.
0
 
LVL 7

Assisted Solution

by:EYoung
EYoung earned 50 total points
ID: 33683013
Dim mYear as integer
If Val(Mid(Format(Now(),"MM/dd/yyyy"), 1, 2)) > 9 Then
   mYear = Val(Mid(Format(Now(),"MM/dd/yyyy"), 7, 4)) + 1
EndIf
mYear = Mid(Str(mYear), 3, 2)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 17

Accepted Solution

by:
Zhaolai earned 200 total points
ID: 33683048
Ooops, my bad...
Try this:
AcnYear = DateTime.Now.AddYears(1).Year.ToString.SubString(2)

0
 
LVL 28

Expert Comment

by:sybe
ID: 33683481
Why don't you just add 3 months to the current date, and then get the year.

<%
Year = Year(DateAdd("m", 3, Now()))
%>

and if you just want the last 2 numbers: subtract 2000:

<%
Dim YourWantedYear As Integer = Year(DateAdd("m", 3, Now())) - 2000
%>

(I know I use VBScript functions, they work in vb.net as well)
0
 
LVL 28

Expert Comment

by:sybe
ID: 33683497
> If the month is greater than 9 i need to go to the next year 2011 but i just want the 11 part, if it is less than 9 i want to stay witht eh current fical year.

You are missing the part when the month is exactly 9.
0
 

Author Closing Comment

by:kdeutsch
ID: 33683908
Thanks
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now