Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date time conversion

Posted on 2007-03-17
5
Medium Priority
?
164 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 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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