Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Short dates coming up in US format if day is less then 13

Does anyone know why my short date formatting comes up in US format, if the
day is less than 13. My regional setting are UK only and dd/MM/yyyy. The
long date settings are fine (sample code that I have been using is below)

Many thanks

James


Sub testdate()

Cells(1, 1).Value = Now - 2 ' gives correct date and time (10th of
February)
Cells(2, 1).Value = Format(Now - 2, "Long date") ' gives correct date
(10th of February)
Cells(3, 1).Value = Format(Now - 2, "D/MMM/YYYY") ' gives correct
date(10th of February)



Cells(4, 1).Value = Format(Now - 2, "Short date") ' gives wrong date
(2nd of October)
Cells(5, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
Cells(6, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Short dates coming up in US format if day is less then 13

Hi James,

Try:

CDate(Format(Now - 2, "dd/mm/yyyy"))

---
Regards,
Norman



"
wrote in message ...
Does anyone know why my short date formatting comes up in US format, if
the
day is less than 13. My regional setting are UK only and dd/MM/yyyy. The
long date settings are fine (sample code that I have been using is below)

Many thanks

James


Sub testdate()

Cells(1, 1).Value = Now - 2 ' gives correct date and time (10th of
February)
Cells(2, 1).Value = Format(Now - 2, "Long date") ' gives correct date
(10th of February)
Cells(3, 1).Value = Format(Now - 2, "D/MMM/YYYY") ' gives correct
date(10th of February)



Cells(4, 1).Value = Format(Now - 2, "Short date") ' gives wrong date
(2nd of October)
Cells(5, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
Cells(6, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Short dates coming up in US format if day is less then 13

Damn US dates!

I tend to cast dates

Cells(1, 1).Value = Now - 2 ' gives correct date and time (10th of
February)
Cells(2, 1).Value = Format(Now - 2, "Long date") ' gives correct date
(10th of February)
Cells(3, 1).Value = Format(Now - 2, "D/MMM/YYYY") ' gives correct
date(10th of February)

Cells(4, 1).Value = CDate(Format(Now - 2, "Short date")) ' gives wrong
date (2nd of October)
Cells(5, 1).Value = CDate(Format(Now - 2, "dd/mm/YYYY")) ' gives wrong
date (2nd of October)
Cells(6, 1).Value = CDate(Format(Now - 2, "dd/mm/YYYY")) ' gives wrong
date (2nd of October)


--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"
wrote in message ...
Does anyone know why my short date formatting comes up in US format, if

the
day is less than 13. My regional setting are UK only and dd/MM/yyyy. The
long date settings are fine (sample code that I have been using is below)

Many thanks

James


Sub testdate()

Cells(1, 1).Value = Now - 2 ' gives correct date and time (10th of
February)
Cells(2, 1).Value = Format(Now - 2, "Long date") ' gives correct date
(10th of February)
Cells(3, 1).Value = Format(Now - 2, "D/MMM/YYYY") ' gives correct
date(10th of February)



Cells(4, 1).Value = Format(Now - 2, "Short date") ' gives wrong date
(2nd of October)
Cells(5, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
Cells(6, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Short dates coming up in US format if day is less then 13

Thanks Norman and Bob

"Norman Jones" wrote:

Hi James,

Try:

CDate(Format(Now - 2, "dd/mm/yyyy"))

---
Regards,
Norman



"
wrote in message ...
Does anyone know why my short date formatting comes up in US format, if
the
day is less than 13. My regional setting are UK only and dd/MM/yyyy. The
long date settings are fine (sample code that I have been using is below)

Many thanks

James


Sub testdate()

Cells(1, 1).Value = Now - 2 ' gives correct date and time (10th of
February)
Cells(2, 1).Value = Format(Now - 2, "Long date") ' gives correct date
(10th of February)
Cells(3, 1).Value = Format(Now - 2, "D/MMM/YYYY") ' gives correct
date(10th of February)



Cells(4, 1).Value = Format(Now - 2, "Short date") ' gives wrong date
(2nd of October)
Cells(5, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
Cells(6, 1).Value = Format(Now - 2, "dd/mm/YYYY") ' gives wrong date
(2nd of October)
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
format cell for keyboard short cut entry only? Darrell[_2_] Excel Worksheet Functions 2 February 12th 10 02:53 PM
Storing data in Short Date format TESA0_4 New Users to Excel 2 July 22nd 08 01:25 AM
Large format prints cut short Dakst Excel Discussion (Misc queries) 2 May 15th 08 06:00 PM
dates in pivot not coming up with years BorisS Excel Programming 7 November 4th 05 03:22 PM
emailed docs coming back in different format JL Adamson Excel Discussion (Misc queries) 0 October 5th 05 04:43 PM


All times are GMT +1. The time now is 02:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"