Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com