Transform string (date and time)

Asked

Viewed 405 times

0

It’s an xml sitemap (google news) and I have to get it out like this:

<news:publication_date>2019-02-19T18:57:26-03:00</news:publication_date>

My fields are in the following format, both strings:

date= 19/02/2019 hour= 18:38:25

Can be in MYSQL or ASP Classic.

  • You want to concatenate the fields ? concat don’t suit you ? Add to question what you have tried for this problem.

  • Concatenate is the least, how to transform date and time, are in separate fields, in string, and displayed in Brazilian standard for fields in American standard, as is the question.

  • string data = Convert.Todatetime("2019-02-19T19:18:20-03:00"). Tostring("dd/MM/yyyy") - Try this after making a Concat in the fields. Wouldn’t solve your problem?

  • is Asp 3. Asp classic

  • @Leonardol updated the question, I think it’s now clearer.

  • ASP Classic is without . NET? Relying only on Vbscript objects?

  • 1

    yes. Asp 3 sheep Asp vab

Show 2 more comments

1 answer

1


In that link you will find the Vbscript functions for time and date handling in ASP Classic.

To solve your problem first you will take the current system date and time and put in a variable data and another time.

<%
  Rem essas variáveis já deve ter sido declaradas em seu código
  Rem fica apenas como parte do exemplo
  dim data
  dim hora
  data = Now
  hora = Time
%>

Then use the functions Year(data) to extract the year, Month(data) to extract the month and Day(data) to extract the day and mount the sentence according to your need.

<%
  response.write("<news:publication_date>" & Year(data) & "-" & Month(data)& "-" & Day(data) & "T" & hora & "-03:00" & "</news:publication_date>")
%>
  • It’s been a long time since I’ve touched this if you have any syntax error feel free to edit the answer.

  • opa, thank you very much. What is this "T" and this "-03:00" a fixed value? Is it a time zone parameter?

  • @Rod: T-3:00 is the time zone and relation to Greenwich. T comes from Translation(translation) from Greenwich.

  • I see here that this value sometimes varies to "-02:00". I do not know what standard is this that google news asks.

  • Each location has a different zone. If the news was aired in São Paulo the T-3:00. If it is aired here in Campo Grande the T-4:00.

  • 1

    got it. I’m going to concatenate the dates with this fixed value of -03:00 so, we’re from the river. There’s the question of daylight saving right.

  • 1

    @Rod already ok, I even took the comment.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.