Solved

Date time conversion

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

615 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