Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Get year portion of the date

Posted on 2010-09-15
Medium Priority
371 Views
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
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
``````
0
Question by:kdeutsch
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 2
• 2
• 2
• +2

LVL 17

Expert Comment

ID: 33682922
0

LVL 1

Expert Comment

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

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

EYoung earned 200 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

LVL 17

Accepted Solution

Zhaolai earned 800 total points
ID: 33683048
Try this:

0

LVL 28

Expert Comment

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

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

ID: 33683908
Thanks
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month4 days, 23 hours left to enroll

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

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