[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

date fomatting struggles

Hi

I am having trouble formatting my date and time so that it can be sent to a mysql database

the table has column
receiving_date as type Date
From MySQL Manual
A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows you to assign values to DATE columns using either strings or numbers.

receiving_time as type Time  
A time. The range is '-838:59:59' to '838:59:59'. MySQL displays TIME values in 'HH:MM:SS' format, but allows you to assign values to TIME columns using either strings or numbers.

My function is this

Public Function getTime() As DateTime
        Dim currentTime As DateTime

        'get system time

        currentTime = DateTime.Now

        Return currentTime
    End Function

So now I need to format the date so I get YYYY-MM-DD and time to be HH:MM:SS

I was going to individually parse the date and format a new string into those two formats but I was hoping there was a better way of formatting it right in the function and returning the necessary info cuz I use this function in a couple places

thx
0
foobarr
Asked:
foobarr
  • 3
  • 2
2 Solutions
 
maidinhtaiCommented:
Do you mean:
Dim currentTime As DateTime
currentTime = DateTime.Now
Messagebox.show(currentTime.ToString("yyyy-MM-dd"))
Messagebox.show(currentTime.ToString("hh:mm:ss"))
0
 
wtconwayCommented:
Just a note to maidinhtai's comment:

Note that the format strings are case senstive. So this won't work properly:

Now.ToString("yyyy/mm/dd")

you should get 2006/00/4 for today. So make sure you use "MM" and not "mm"

That drove me crazy when I was researching it a while back. Here's a good sample from Microsoft. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasstostringtopic3.asp

Good luck.
0
 
foobarrAuthor Commented:
wouldn't I need
Now.ToString("YYYY-MM-DD")
Now.ToString("HH:MM:SS")

then?

i will give it a try later on and post back


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
wtconwayCommented:
well not necessarily. When I say case sensitive, I mean that I know MM and mm do not return the same results.
0
 
foobarrAuthor Commented:
Dim currentTime As Date

        Dim currentDate As Date


        currentTime = Date.Now
        currentDate = Date.Now



        MessageBox.Show("Current Date: " & currentDate.ToString("yyyy-MM-dd"))
        MessageBox.Show("Current Time: " & currentTime.ToString("HH:MM"))


this seemed to work
0
 
foobarrAuthor Commented:
actualy the last one was

MEssagebox.show("CurrentTime: " & currentTime.toString("HH:mm"))
0

Featured Post

Technology Partners: 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!

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