Solved

Date time conversion

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 Application Installation with sqlserver 8 69
VB.Net  Exporting Excel Woorkbook to PDF 7 72
Send SMS from vb.net desktop app 30 51
Convert VB web project to C# 3 66
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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