Link to home
Start Free TrialLog in
Avatar of NessieB
NessieBFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Date format question

My system date format is yy-MM-dd

I want my program to always format date as dd/mm/yyyy

I used

dim dd as date

dd=format(dd,"dd/mm/yyyy")

but dd keeps displaying yy-MM-dd

What is the correct code please?
SOLUTION
Avatar of ADSaunders
ADSaunders

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softplus
softplus

Hi NessieB,
You're mixing strings with dates :) - date fields always store just the date, the formatting part is in the string itself.
In other words, what you probably want:
dim dd as date
dim ss as string
ss = format(dd, "dd/MM/yyyy")
here you are storing the formatted date as a string (MM needs to be in upper case)
John
ADSaunders, a little behind you...

Another thing to add, the Date Function always returns a Varient, at least that is what the MSDN says... "Returns a Variant (Date) containing the current system date." - MSDN

Stick with varients here NessieB
NessieB,
The only way to always get the date formatted in that way is to change the default date format in Regional settings in the control panel. However you must be aware that this will not just affect output from VB, and if your program is to be run on other systems, you may not be able to predict (or control) the regional date format on the target machine.
.. Alan
Don't stick with variants, ouch! You're just saving a string of a few characters, why add the massiv overhead for variants? You could also use ss = format$(...) if you want to be sure (not needed in vb.net), but please don't save the result in a variant  :)
John
oh come on softy, a couple of varients never hurt anyone..... If this guy is writing some huge enterprise software, I could understand not wanting to use varients, but I doubt he is....
Avatar of NessieB

ASKER

Ok - thanks for the help - split points for you.
> oh come on softy, a couple of varients never hurt anyone
:)
Softplus,

I feel like the friendly neighborhood drug dealer now.... Hey kid, "a couple of varients never hurt anyone"

hehe
what else are you dealing? :)) Got any good queries?
Well,

I usually only deal in bad data types... But since your apparently a query junk, I would recommend googling "marble" + "dynamite", I hear it will blow your rocks off.

Mugman