Date Format error on different PCs

G

Guest

Hi all,

I'm working on formatting dates when parsing a file. I've run into a
problem when another user ran some report updates from their computer (when
it's usually done on mine), and the date format is completely off.

The date values are different, and I can't find a way to solve the problem.
Every test I've run keeps getting the same result.

The error:
I read a string value of 11/12/06 as 11/12/2006 (mm/dd/yyyy).
The other computer reads 11/12/06 as 12/6/2011 (mm/dd/yyyy).

I'm drawing a complete blank on how to solve this.

I've tried using CDate("11/12/06"). I have to parse the day/month/year
values from a larger string, so I am using variables. I can't find a way to
use date literals (#) when using string values.

Here's the things I've tried to do (some are probably dumb, but I was
desparate).
datestring = "11/12/06"
Date = CDate(datestring)
vMO = "11", vDY = "12", vYR = "06";
Date = vMO & "/" & vDY & "/" & vYR;
Date = "#" & vMO & "/" & vDY & "/" & vYR & "#";
datestring = "#" & vMO & "/" & vDY & "/" & vYR & "#";
Date = datestring;

Is there a way I can set individual parts of a date? like Month(ddate) =
"12";

Any help is appreciated. I'm stuck and I'm willing to try anything (except
do something on the other person's computer, because I can't).

Thanks,
Jay
 
G

Guest

Hi all,

I'm working on formatting dates when parsing a file. I've run into a
problem when another user ran some report updates from their computer (when
it's usually done on mine), and the date format is completely off.

The date values are different, and I can't find a way to solve the problem.
Every test I've run keeps getting the same result.

The error:
I read a string value of 11/12/06 as 11/12/2006 (mm/dd/yyyy).
The other computer reads 11/12/06 as 12/6/2011 (mm/dd/yyyy).

I'm drawing a complete blank on how to solve this.

I've tried using CDate("11/12/06"). I have to parse the day/month/year
values from a larger string, so I am using variables. I can't find a way to
use date literals (#) when using string values.

Here's the things I've tried to do (some are probably dumb, but I was
desparate).
datestring = "11/12/06"
Date = CDate(datestring)
vMO = "11", vDY = "12", vYR = "06";
Date = vMO & "/" & vDY & "/" & vYR;
Date = "#" & vMO & "/" & vDY & "/" & vYR & "#";
datestring = "#" & vMO & "/" & vDY & "/" & vYR & "#";
Date = datestring;

Is there a way I can set individual parts of a date? like Month(ddate) =
"12";

Any help is appreciated. I'm stuck and I'm willing to try anything (except
do something on the other person's computer, because I can't).

Thanks,
Jay
 
G

Guest

Klatuu, you've done it again!

I changed the dates to read as 06-11-12 and then added '20' at the front to
give me 2006-11-12. Now if works regardless of regional settings.

Thanks again!
 
G

Guest

Good idea, Jay. Glad I could help.

Jay said:
Klatuu, you've done it again!

I changed the dates to read as 06-11-12 and then added '20' at the front to
give me 2006-11-12. Now if works regardless of regional settings.

Thanks again!
 
R

RoyVidar

Jay said:
Hi all,

I'm working on formatting dates when parsing a file. I've run into a
problem when another user ran some report updates from their computer
(when it's usually done on mine), and the date format is completely
off.

The date values are different, and I can't find a way to solve the
problem. Every test I've run keeps getting the same result.

The error:
I read a string value of 11/12/06 as 11/12/2006 (mm/dd/yyyy).
The other computer reads 11/12/06 as 12/6/2011 (mm/dd/yyyy).

I'm drawing a complete blank on how to solve this.

I've tried using CDate("11/12/06"). I have to parse the
day/month/year values from a larger string, so I am using variables.
I can't find a way to use date literals (#) when using string
values.

Here's the things I've tried to do (some are probably dumb, but I was
desparate).
datestring = "11/12/06"
Date = CDate(datestring)
vMO = "11", vDY = "12", vYR = "06";
Date = vMO & "/" & vDY & "/" & vYR;
Date = "#" & vMO & "/" & vDY & "/" & vYR & "#";
datestring = "#" & vMO & "/" & vDY & "/" & vYR & "#";
Date = datestring;

Is there a way I can set individual parts of a date? like
Month(ddate) = "12";

Any help is appreciated. I'm stuck and I'm willing to try anything
(except do something on the other person's computer, because I
can't).

Thanks,
Jay

I'd suggest looking into the DateSerial function, which accepts the
year, month and day. Simple sample, without bothering about century...

dim s as string
dim dt as date

s = "11/12/06"
dt = dateserial(cint("20" & right$(s, 2)), _
cbyte(left$(s, 2)), _
cbyte(mid$(s, 3, 2)))
debug.print dt
 
R

RoyVidar

RoyVidar said:
I'd suggest looking into the DateSerial function, which accepts the
year, month and day. Simple sample, without bothering about
century...

dim s as string
dim dt as date

s = "11/12/06"
dt = dateserial(cint("20" & right$(s, 2)), _
cbyte(left$(s, 2)), _
cbyte(mid$(s, 3, 2)))
debug.print dt

Oh dear, typos (found at least one), sorry

Replace the last line with
cbyte(mid$(s, 4, 2)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top