Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Conversion 1

Status
Not open for further replies.

kennedymr2

Programmer
May 23, 2001
594
AU
I seem to be stuck with a data conversion..!@!!
I possibly have had a brain fade..

1. If a date is eg 31st December 2010 how do i get it to 31/12/2010

2. How do i convert todays date eg date() now() to eg 31st December 2010

Really appreciate some help

Regards Kennedymr2
 
I'm not merely pointing out that vB.net has TRUE type casting whereas VB6 does not.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
>I'm not sure why this is such a seldom understood point

Possible because that's the narrow Computer Science definition of casting for ALGOL-based languages,of which C is one, but which technically VB is not. We should also note that Wikipaedia and other sources quite happily state that "In the C family of languages, the word cast typically refers to an explicit type conversion (as opposed to an implicit conversion), regardless of whether this is a re-interpretation of a bit-pattern or a real conversion

>Vb.Net when using "Option Strict On" sure ...
> ... pointing out that vB.net has TRUE type casting

If we are discussing dilettante's narrow definition of casting, then this is incorrect, as Option Strict is purely related to implicit conversion.

VB6 can do implicit and explicit conversion/coercion, and is also capable of explicit casting.

Here's how we can do an explicit cast:
Code:
[blue]Option Explicit

Private Type fred
    a As Long
End Type
    
Private Type jim
    a(1 To 4) As Byte
End Type

Private Type bob
    a As String * 2
End Type

Private Type wombat
    a As Single
End Type
    

Public Sub CastExample()
    Dim fredt As fred
    Dim jimt As jim
    Dim bobt As bob
    Dim wombatt As wombat
    
    
    fredt.a = &H670065
    
    LSet jimt = fredt ' explicit cast from a long to a 4 element array of bytes
    LSet bobt = fredt ' explicit cast from a long to a two character Unicode string
    LSet wombatt = fredt ' explicit cast to a single
    
    Debug.Print LenB(fredt), LenB(jimt), LenB(bobt), LenB(wombatt) ' demonstrates underlying memory is the same as per dilettante's requirement
    
    MsgBox fredt.a ' our original
    MsgBox jimt.a(1) & "," & jimt.a(2) & "," & jimt.a(3) & "," & jimt.a(4) ' now as array contents
    MsgBox bobt.a ' now as a string
    MsgBox wombatt.a ' now as a single

End Sub[/blue]



 
And I thought I could be pedantic :D



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top