Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date format

Posted on 2004-08-17
2
Medium Priority
?
230 Views
Last Modified: 2012-05-05
Hi,
i'm new to vb .net, i have some problem of formatting date time. i take user input of month and year and need to convert it into a date range, let say, 7,2004 need to be converted to 7/1/2004 to 7/31/2004. How do i convert the 7 and 2004 into a date type? can i do deduction of date?like if i deduct 3/1/2004 it wil gives me 2/29/2004??
0
Comment
Question by:sinwee80
[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 Comments
 
LVL 1

Expert Comment

by:jzwaenepoel
ID: 11818920
Have you tried the DateTime.Parse (or ParseExact) - methods?

Hope this helps,

Joris
0
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 400 total points
ID: 11819122

Joris is right, but this is not the full code,.. since you need a try-catch-statement to filter formats like these: "1/12004" in stead of "1/1/2004".

>>>> you need this code (I used a textbox, a button and a label):


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Label1.Text = DateTime.Parse(TextBox1.Text).ToString
        Catch ex As Exception
            MsgBox("Date not recognised")
        End Try
    End Sub



>>>> The Deduct-question...  Use the same setting as before (with textbox, button and label) but now with a EXTRA textbox. Put this code to your app:


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim yourdate As DateTime
        Try
            yourdate = DateTime.Parse(TextBox1.Text)
            yourdate = yourdate.AddDays(-1 * Val(TextBox2.Text))
            Label1.Text = yourdate
        Catch ex As Exception
            MsgBox("Date not recognised")
        End Try
    End Sub


I this case your date will be deducted by the #number of days you fill into the textbox2 !!!


Try it and maybe you like it!

Daniël
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
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

610 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