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

  • Home
  • SEARCH
  • 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 8890677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:33:24+00:00 2026-06-14T22:33:24+00:00

I’m working on a VBA script in Excel 2010 that picks up certain events

  • 0

I’m working on a VBA script in Excel 2010 that picks up certain events from a MySQL database based on the dates of the events. The dates in the database are stored in a “yyyy-mm-dd hh:mm:ss” . My users will be using a from-to date range to filter the events they are interested in. To make it easier for them I use two calendar controls (mscal.ocx) for the range – Calendar1 for from and Calendar2 for to. I wrote two simple subroutines to make sure that every click on the calendars automatically updates cells from which i take data for the query string, which looks like this :

Private Sub Calendar1_Click()

Dim date1, datetime1, time1 As Date

Cells(29, 10) = CDbl(Calendar1.Value)
Cells(29, 10).NumberFormat = "yyyy-mm-dd"
Cells(30, 10).NumberFormat = "hh:mm:ss"
Cells(31, 11).NumberFormat = "yyyy-mm-dd hh:mm:ss"

date1 = Cells(29, 10)
time1 = Cells(30, 10)
datetime1 = date1 & " " & time1
Cells(31, 10) = datetime1


Cells(29, 10).Select

End Sub

Private Sub Calendar2_Click()

Dim date2, datetime2, time2 As Date

Cells(29, 11) = CDbl(Calendar2.Value)
Cells(29, 11).NumberFormat = "yyyy-mm-dd"
Cells(30, 11).NumberFormat = "hh:mm:ss"
Cells(31, 11).NumberFormat = "yyyy-mm-dd hh:mm:ss"

date2 = Cells(29, 11)
time2 = Cells(30, 11)
datetime2 = date2 & " " & time2
Cells(31, 11) = datetime2


Cells(29, 11).Select
End Sub

And well, it almost does what I want it to do, which is change the format that is given by the calendar control, which is dd/mm/yyyy to yyyy-mm-dd. Yes, almost, because it only works as long as the day value is between 1 and 12, then my datetime cell is displayed properly as “yyyy-mm-dd hh:mm:ss”. For 13 to 31 day value my datetime cell does not get formatted and instead displays as “dd/mm/yyyy hh:mm:ss”.

Now, it’s worth noting, that Cells 29,10 and 29,11 ALWAYS have the proper formatting (yyyy-mm-dd) regardless of the date, the problem is with Cells 31,11 and 31,10.

Now, when i doubleclick the cell, get cursor flashing in it and press enter, the formatting is executed and the format changes to proper format (even for day value between 13 and 31). However the purpose of this is to automate everything as much as possible, so that’s not really a solution. I can attach the file if needed, because I do realise it sounds a bit ridiculous that it works for certain values and not for others.

Please help !

EDIT ::

Ok, thanks again for fast answer, I checked your solution and with it I’m kind of back to the beggining. Using

Private Sub CommandButton1_Click()

Dim date1, date2, datetime1, datetime2, time1, time2, time3 As Date

date1 = Cells(29, 10)
time1 = Cells(30, 10)
datetime1 = Format(date1, "dd/mm/yyyy") & " " & Format(time1, "hh:mm:ss")
Cells(31, 10) = datetime1

End Sub

Works great, BUT works only if the day value is from 1 to 12, for example, for Cell values

Date

2012-09-12

Time

15:00:00

The answer is as I want it, which is

Datetime

2012-09-12 15:00:00

BUT as soon as I put the day value anything above 12, which is 13 to 31 it stops working properly (yes I know how ridiculous it sounds) and the result I get instead is :

Datetime

13/09/2012 15:00:00

Any suggestions greatly appreciated…

  • 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-06-14T22:33:26+00:00Added an answer on June 14, 2026 at 10:33 pm

    I know I’m too late, But I think you need to differentiate between months (MM) and minutes (mm)…So try this…

    Format(yourDateObj, "yyyy/MM/dd hh:mm:ss");
    

    Hope this Helps..:)

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.