Solved

Date time conversion

Posted on 2007-03-17
5
157 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

20 Experts available now in Live!

Get 1:1 Help Now