.NETGURU
convert to date format
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.

Post a new message to this list...

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

--
_____
DC G

Reply to this message...
 
    
Lucas Tam
"DC Gringo" <Click here to reveal e-mail address> wrote in news:e2T7mLQlEHA.3968
@TK2MSFTNGP11.phx.gbl:

[Original message clipped]

Use the function FormatDateTime

--
Lucas Tam (Click here to reveal e-mail address)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Reply to this message...
 
    
DC Gringo
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

"Lucas Tam" <Click here to reveal e-mail address> wrote in message
news:Xns955D8D12F394Fnntprogerscom@140.99.99.130...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
What variable type is pubLatest? Turn Option Strict On!!!

Greg

"DC Gringo" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Lucas Tam
"DC Gringo" <Click here to reveal e-mail address> wrote in news:OgmGIYQlEHA.1904
@TK2MSFTNGP09.phx.gbl:

[Original message clipped]

I posted the wrong function...

Give Format a try.

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vblr7/html/vafctformatdatetime.asp

--
Lucas Tam (Click here to reveal e-mail address)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Reply to this message...
 
    
Greg Burns
Dim s As String = FormatDateTime(DateTime.Now, DateFormat.ShortDate)

s = "9/7/2004"

works for me

Greg

"Lucas Tam" <Click here to reveal e-mail address> wrote in message
news:Xns955D91920CC83nntprogerscom@140.99.99.130...
[Original message clipped]

Reply to this message...
 
    
Brian
Did you try pubLatest.ToShortDateString()?

Brian

"DC Gringo" wrote:

[Original message clipped]

Reply to this message...
 
    
DC Gringo
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" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
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

"DC Gringo" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
DC Gringo
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

"Greg Burns" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
<sigh> :^)

You turn on Option Strict to discover where you are making implicit castings
at. And that is exaclty what it did.

[Original message clipped]

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

"DC Gringo" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
DC Gringo
Greg,

You are the man...it worked!

Sorry for the density upstairs over here...

_____
Glenn

"Greg Burns" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Greg Burns
I need a cigarette. And I don't even smoke. :^)

"DC Gringo" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mythran
Dim pubLatest As String

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

Mythran

"DC Gringo" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.DateTime
System.Diagnostics.Debug
System.Object




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification