Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Strange Date

Hi,

I have a strange problem with date.

I retrieved a value from another application as string which is supposed to be a date. But when I change it to date, it turns upside down!

For example, the value I retrieved is 20-09-04 where 20 is day, 09 is month and 04 is year. When I store it in a date variable, it turns to 9/4/2020. I even tried formatting it to "dd/mm/yy", but still the same. Please help.

Thanks
0
shersu
Asked:
shersu
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
Hi shersu,


As the value is a string, you will have to strip it apart and construct your own date.

day = left('20-09-04', 2)
month = mid('20-09-04', 4, 2)
year = '20' & right('20-09-04', 2)

I think there is a date function to build a date (dateserial(day, month, year) maybe).



Regards,

Richard Quadling.
0
 
Richard QuadlingSenior Software DeverloperCommented:
shersu,

dt_date = dateserial(year, month, day)

Regards,

Richard.
0
 
Ryan ChongCommented:
Always format your date values into format of YYYY/MM/DD or MM/DD/YYYY or DD MMM YYYY (or similar formats) when save into database, regardless your server settings.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Richard QuadlingSenior Software DeverloperCommented:
There is an ISO standard for dates

CCYY-MM-DD HH:MM:SS.SSS

This can be extended to include timezones.
0
 
GrahamSkanRetiredCommented:
That will happen if your Windows regional setting for Short Date is yy-mm-dd
0
 
shersuAuthor Commented:
But since this is a network program, everybody on the network will have different regional settings. So I wish to set up the code in such a way that the date is standardised regardless of the system date format.

Thanks
0
 
Richard QuadlingSenior Software DeverloperCommented:
Then always format the date the way YOU want to.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now