print date sends me back "04-07-2018"
I would like to have "07/04/2018"
currently I am doing
Code: Select all
datef=mid(date,4,2)&"/"&left(date,2)&"/"&right(date,4)
regards
Code: Select all
datef=mid(date,4,2)&"/"&left(date,2)&"/"&right(date,4)
Code: Select all
#include "vbcompat.bi"
Print Format(Now, "dd/mm/yyyy")
Sleep
Code: Select all
' MyDate_Func.bas -- 2018-04-07, MrSwiss
'
' compile: -s console
'
' needed here, because: it is called, before the implementation!
Declare Function MyDate( ByVal nChr As UByte=0 ) ByRef As Const String
' ===== Start test/demo code =====
Print Date; Tab(16); "original american date"
Print MyDate(); Tab(16); "same delimtter, as above! (day/month swapped)"
Print MyDate( Asc("/") ); Tab(16); "new delimtter! (day/month swapped)"
Print MyDate( Asc(".") ); Tab(16); "new delimtter! (day/month swapped)"
Print
For i As UInteger = 1 To 3
Print Mydate( Asc(".") )
Next
Print : Print "press a key, to exit ! ";
Sleep
' ===== End test/demo code =====
' ----- start implementation -----
Function MyDate( _ ' day/month swap (optional: 'user defined' delim.)
ByVal nChr As UByte=0 _ ' default = american delim.
) ByRef As Const String ' reference to cDate (Static, read only!)
Static As String cDate, aDate ' local static var's
' check for: delimitter- or date-change (update not made otherwise!)
If nChr <> Asc(Mid(cDate, 3, 1)) OrElse aDate <> Date Then
aDate = Date ' update aDate (american, for comparison!)
If nChr > 0 Then ' 'user defined' delim.? --> build cDate
cDate = Mid(aDate, 4, 2) + Chr(nChr) + Left(aDate, 2) + _
Chr(nChr) + Right(aDate, 4)
Else ' default, american delim. used
nChr = Asc(Mid(aDate, 3, 1)) ' get delim. --> build cDate
cDate = Mid(aDate, 4, 2) + Chr(nChr) + Left(aDate, 2) + _
Chr(nChr) + Right(aDate, 4)
End If
End If
' return pre-made or newly created cDate-String (on change, only!)
MyDate = cDate ' the same as: Function = cDate / Return cDate
End Function
' ----- end implementation ----- ' ----- EOF -----
Maybe, but so much simpler for the same result:MrSwiss wrote:Alternative: use your own, customizable Function, which has the advantage, of
not needing, any #Include "whatever.bi" ... (cluttering up, the name-space).
.....
Code: Select all
#include "vbcompat.bi"
Print Date
Print Format(Now, "dd-mm-yyyy")
Print Format(Now, "dd/mm/yyyy")
Print Format(Now, "dd.mm.yyyy")
Sleep
Code: Select all
Print Format(Now, "dd-mm-yyyy")
' versus
Print MyDate( Asc("/") ) ' and the Asc("/") is optional, too
Print MyDate( ) ' default = american delimiter
Print MyDate( 46 ) ' second option: get the value straight from: ASCII-Table "."
Print MyDate( 47 ) ' second option: get the value straight from: ASCII-Table "/"
Code: Select all
'Pgm testdate
'Mettre la date dans un autre format d'affichage
' Utisation d'une constante comme délimiteur
Const CDelim="/"
Dim NewDate as String
NewDate=Mid(date,4,2) & CDelim & Left(date,2) & CDelim & Right(date,4)
Print "Date origine ",date
Print "Date modif ",NewDate
Sleep
When the values are taken out of context.MrSwiss wrote:since when, is the ASCII-Table, considered *undefined* ???
Of course, ptitjoz could restart the program every 24 hours, but if that is not an acceptable workaround, here is the solution for updating (hit Ctrl C to exit):MrSwiss wrote:your solution works, but it isn't updated, e.g. date change, while program is running.
Code: Select all
'Pgm testdate
'Mettre la date dans un autre format d'affichage
' Utisation d'une constante comme délimiteur
Const CDelim="/"
Dim NewDate as String
Dim NewTime as String
NewDate=Mid(date,4,2) & CDelim & Left(date,2) & CDelim & Right(date,4)
Print "Date origine ",date
Print "Date modif ",NewDate
While 1
NewTime=Mid(time,4,2) & CDelim & Left(time,2) & CDelim & Right(time,4)
Print "Time origine ",time
Print "Time modif ",NewTime
Sleep 1000
Wend