Solved

Date format

Posted on 2004-08-17
2
227 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 100 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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