convert to date format

  • Thread starter Thread starter DC Gringo
  • Start date Start date
D

DC Gringo

How can I convert this pubLatest to a date with format "m/d/yyyy"?

Dim pubLatest As New Date
pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value
 
Thank you...

The only thing that did was set my time to 12:00

pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

______
DC G
 
What variable type is pubLatest? Turn Option Strict On!!!

Greg

DC Gringo said:
Thank you...

The only thing that did was set my time to 12:00

pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

______
DC G
 
Dim s As String = FormatDateTime(DateTime.Now, DateFormat.ShortDate)

s = "9/7/2004"

works for me

Greg
 
Still no luck...neithr of these work...they both return times...

Could it be because of my declaration?

Public pubLatest As Date
pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value
pubLatest.ToShortDateString()



Brian said:
Did you try pubLatest.ToShortDateString()?

Brian
 
Place Option Strict On at the top of your file!!!

When you do you will see this will not compile:

Public pubLatest As Date
pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

Without Option Strict you are just playing a casting game. Casting a
sqldate to a string back to a date

If you want to format it for display, then stuff the result of either method
into a STRING, not a date variable.

Greg
 
Thanks, Greg, we're getting there...still have some compile errors, though.

pubLatest = Me.SqlSelectCommand1.Parameters("@pubLatest").Value
pubLatest.ToShortDateString()

Give me error: 'ToShortDateString' is not a member of 'String'.


-- and --

Public pubLatest As Date
pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

Gives me error: "Option Strict On disallows implicit conversions from
'System.Object' to 'Date'."

_____
DC G
 
<sigh> :^)

You turn on Option Strict to discover where you are making implicit castings
at. And that is exaclty what it did.
Public pubLatest As Date
pubLatest =
FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

Gives me error: "Option Strict On disallows implicit conversions from
'System.Object' to 'Date'."

Like I said, you are trying to shove a string (the result of either function
is a string, not a date) into a date variable. Hence "Option Strict On
disallows implicit conversions from 'System.Object' to 'Date'."

Don't do that!

If you want to display a date variable (pubLatest), then you must convert it
to a string (using either method). Both of the functions return a STRING,
not a DATE. So you cannot store it back into a DATE variable. (Well, you
can with Option strict off, but it is just casting it back to a DATE
implicitly.)

Make a new variable (say "s")

Public s As String
s = FormatDateTime(Me.SqlSelectCommand1.Parameters("@pubLatest").Value,
DateFormat.ShortDate)

Now use "s" to display it your date variable as a formatted string.

Debug.Writeline(s)

Greg
 
Dim pubLatest As String

pubLatest =
CDate(Me.SqlSelectCommand1.Parameters("@pubLatest").Value).ToShortDateString()


Mythran
 
Greg,

You are the man...it worked!

Sorry for the density upstairs over here...

_____
Glenn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top