Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert date function 2

Status
Not open for further replies.

axLW

Programmer
Feb 6, 2015
110
GB
Hello, I have a date

dd/mm/yyyy

I need to convert it to standard XSD format:

yyyy-mm-dd

So:

01/12/2016 needs to become 2016-12-01

Have no idea how to change the order of characters in a string.

Thanks

 
Do you want to do this in VBScript or Javascript?

Basically, you get the day, month and year as numbers and reassemble it the other way round. There is no built in function with fancy formatting to do this.
 
Yep, just a Split function and some concatenation.

Code:
dim olddate
dim newdate
dim arytmp

olddate = "01/12/2016"
arytmp = Split(olddate,"/")

' Array is zero based
newdate = arytmp(2) & "-" & arytmp(1) & "-" & arytmp(0)

msgbox newdate

Swi
 
Thank you both very much. It's working.
 
Ok, I think I need more assistance here (to do with what Chris was saying).

I need to know whether or not the date/time chosen is BST or GMT.

At the moment this is my date/time value:

Code:
"<PickupTime>" & NewDate & "T" & PickupHour & ":" & PickupMinute & ":00+00:00</PickupTime>"

The NewDate field is now formatted correctly using Swi's function, an example of which is:

2012-11-18 = 18 November 2012.

Now each date will only ever be GMT or BST and this will of course depend on the time, date and year.

One date may be BST in 2012 but GMT in 2016.

Is there a protocol to automatically choose the correct time zone based on the date/time?

If the time/date is BST I'll need to plus 1 hour to the time format, like so:


1:23pm on 18 November 2012 (GMT) is: 2012-11-18T13:23:00+00:00

2.53am on 02 June 2012 (BST) is 2012-06-02T02:53:00+01:00


Dear oh dear this is complicated.
 
What is being fed to you for you to figure out if it is GMT or BST?

Swi
 
2012-11-18T13:23:00+00:00

This is the live state of my date time field.

Alternatively I can use:

18/11/2012

I'll need to establish the time zone based on one of those two date time formats
 
If I can basically establish which time zone a date is using 18/11/2012 then I can adjust the longer time/date format accordingly.
 
Correct but is there any indicator of whether the data is in GMT or BST?

Swi
 
Well no. My date is in that format (from my website) and I have to establish whether or not that date is gmt or bst
 
So basically I will be given a date by my customer, for example:

23/12/2015

I then need to establish whether or not that date is GMT or BST (again, the cut off point changes every year so I presume there is a function that checks this automatically).

Once I know whether or not any given date is GMT or BST I can then adjust my full date/time value (which is straightforward).
 
Sorry Chris, I know you are trying to encourage me to find a solution myself but I cannot find any specific examples where you provide a date and the program returns either GMT or BST.

The only DateValue() things I can see online are how to convert or display the date.
 
That is what FormatDateTime() does, you give the function a date string and a formatand if the link to the DevGuru examples is in my first post and if you set the localeID (also in first post) you can set the preferred format rather than it being the SERVER locale, which may or may not be the visitors locale.

Links for locale settings are also in first post.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Ok let me give that at try... thanks.
 
Chris I'm sorry I cannot get my head around this.
I understand you can set the locale ID to UK but the devguru link you provided does not show how to display the date with the time zone attached.

I basically need to submit my date/time value in standard XSD format.

yyyy-mm-ddThh:mm:ss+tzdst

My customers are booking a taxi and they are basically choosing the pickup date for the taxi pickup. It could be any date in the future and the last thing I need to do is establish is whether or not the date they have chosen is GMT or BST (UK Dates Only).

I have converted the date from my website (25/12/2015) to (2015-12-25) and I have my time values already (in minutes and hours).

I'm currently submitting my XML date/time like so:

Code:
<PickupTime>" & NewDate & "T" & PickupHour & ":" & PickupMinute & ":00[i]+00:00[/i]</PickupTime>



If the date is GMT I will need to place +00:00 at the end of the value, if the date is BST I will need to place +01:00 at the end of the value.

Is there any chance you can give me a solution. I've tried my best to make things as clear as possible here.

Here are the notable elements of the code:

Code:
OldDate = "25/12/2015"
PickupHour = "15"
PickupMinute = "30"

AryTmp = Split(OldDate,"/")
NewDate = AryTmp(2) & "-" & AryTmp(1) & "-" & AryTmp(0)

stringXML = "<PickupTime>" & NewDate & "T" & PickupHour & ":" & PickupMinute & ":00+[b]00:00[/b]</PickupTime>"



 
If the date is GMT I will need to place +00:00 at the end of the value, if the date is BST I will need to place +01:00 at the end of the value.

Then you need to use javascript to display the time and date in the locale of the requesting client.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top