Solved

Date time conversion

Posted on 2007-03-17
5
160 Views
Last Modified: 2010-04-23
VB.net 2005
SQL 2005

I have two variable, one contains date and secound time. Booth is the type of string..
How can I do first validation this variable that I'm shure that contains time and date and then convert to type date and time

Regards...
0
Comment
Question by:amaimedia
[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
  • 3
  • 2
5 Comments
 
LVL 27

Expert Comment

by:planocz
ID: 18740423
Can you give us a sample of what your 2 vars look like?
0
 

Author Comment

by:amaimedia
ID: 18740520
yes
Dim x,y as string
x = "31/12/2006"
y = "10:23 AM"
and I try send sql with this
date.Value = CType(x, Date)
and this OK, somethimes in variable x I have
x= "45/35/moi"
and this cause error with conversion CType(x, Date), I try first to validate date, and next I try to do conversion... How can I do that.

0
 
LVL 27

Expert Comment

by:planocz
ID: 18740879
x = "31/12/2006"   Is this the format you want? (dd/MM/yyy)

or do you want  this..... MM/dd/yyyy   ?
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 18741392
Here isa sample of what you can do.....

'Run This.......

 MessageBox.Show(CheckDateTime("31/12/2006", "10:23 AM"))

'ADD this to your Form

  Function CheckDateTime(ByVal x As String, ByVal y As String)
        Dim dob As DateTime
        Dim dobT As DateTime
        ' x = "31/12/2006"
        'y = "10:23 AM"
        Try
            x = x.Substring(3, 2) & "/" & x.Substring(0, 2) & "/" & x.Substring(6)
            dob = CDate(x)
            dobT = CDate(y)
            dobT += dob
            Return dobT
        Catch Exp As System.InvalidCastException
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            Return "Error"
        End Try
    End Function
0
 

Author Comment

by:amaimedia
ID: 18741719
Ok
I Solve this with IsDate Function...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net WebRequest Code from JSON curl 7 87
Get number of Files in Directory and Sub Directories 2 54
VB.NET 2008 Publish Error 2 44
Optimize the query 5 51
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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