ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Short dates coming up in US format if day is less then 13 (https://www.excelbanter.com/excel-programming/353128-short-dates-coming-up-us-format-if-day-less-then-13-a.html)

[email protected][_2_]

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

Norman Jones

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




Bob Phillips[_6_]

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




[email protected][_2_]

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






All times are GMT +1. The time now is 04:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com