Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1114507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:00:59+00:00 2026-05-17T03:00:59+00:00

I’m trying to make my string a nice formatted time but the column in

  • 0

I’m trying to make my string a nice formatted time but the column in the database isn’t set up as a date/time field is there anyway I can do this?

Here’s my query

Dim query as String = "Select * from openquery (devbook, 'SELECT wb.arrival_time FROM web_bookings wb ')"

And here’s where i’m converting it

Session("formattime") = DateTime.Parse(drv.Row("arrival_time")).ToString("hh:mm")

The arrival_time field only has 4 numbers in like this 1000 so I need a way of converting it to a nice format like this 10:00AM

I’m using VB by the way

Any ideas?

Thanks

Jamie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:01:00+00:00Added an answer on May 17, 2026 at 3:01 am

    How about:

    string str = "1000";//drv.Row("arrival_time")
    string[] formats = new string[] { "HHmm" };
    DateTime dt = DateTime.ParseExact(str, formats,
                                        System.Globalization.CultureInfo.InvariantCulture,
                                        System.Globalization.DateTimeStyles.AdjustToUniversal);
    string strTime = dt.ToShortTimeString();
    
    DateTime dte = DateTime.Now;
    IFormatProvider culture = new System.Globalization.CultureInfo("en-GB", true);
    

    VB.NET

    Dim str As String = "1000" 'drv.Row("arrival_time")
    Dim formats As String() = New String() {"HHmm"}
    Dim dt As DateTime = DateTime.ParseExact(str, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal)
    Dim strTime As String = dt.ToShortTimeString()
    
    Dim dte As DateTime = DateTime.Now
    Dim culture As IFormatProvider = New System.Globalization.CultureInfo("en-GB", True)
    

    Outputs:

    10:00 AM

    Alternatively, if you plan on using that frequently, you might want to add that as an extension method.

    public static class Extensions
    {
        public static string ToTime(this string str)
        {
            DateTime dt = DateTime.Now;
            try
            {
                string[] formats = new string[] { "HHmm" };
                dt = DateTime.ParseExact(str, formats,
                                                    System.Globalization.CultureInfo.InvariantCulture,
                                                    System.Globalization.DateTimeStyles.AdjustToUniversal);
            }
            catch
            { throw new Exception("Invalid data"); }
            return dt.ToShortTimeString();
        }
    }
    

    –VB.NET–

    Public NotInheritable Class Extensions
        Private Sub New()
        End Sub
        <System.Runtime.CompilerServices.Extension> _
        Public Shared Function ToTime(str As String) As String
            Dim dt As DateTime = DateTime.Now
            Try
                Dim formats As String() = New String() {"HHmm"}
                dt = DateTime.ParseExact(str, formats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal)
            Catch
                Throw New Exception("Invalid data")
            End Try
            Return dt.ToShortTimeString()
        End Function
    End Class
    

    Example:

    string str = "13000";//drv.Row("arrival_time")
    string strTime = str.ToTime();
    

    VB.NET

    Dim str As String = "13000"
    'drv.Row("arrival_time")
    Dim strTime As String = str.ToTime()
    

    Anything bad in the data will throw you an exception.

    –EDIT–

    Works fine in VB.NET.

    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.