+ Reply to Thread
Results 1 to 17 of 17

change date format of date variable to something like 3/17/14

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    change date format of date variable to something like 3/17/14

    Hi all,

    I have a variable which contains a date value (say date value is in A1). I want to paste this date value into a cell (say A2) but change the format from "mm/d/yyyy" to say "mm/d/yy". Here is the code i use.........but it doesnot work.

    Please Login or Register  to view this content.
    alert_due_date_value is the variable which contains the date........i try to convert its format to mm/d/yy and store result in variable junk1 but the displayed value in junk1 is the same as that for alert_due_date_value........any ideas what to do?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: change date format of date variable to something like 3/17/14

    Is alert_due_date_value a date?
    You could try

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    no actually i think its a variant......because i dont declare it.......i know bad practice

    would being a variant cause the problem

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: change date format of date variable to something like 3/17/14

    Did you try?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    ok tried what you suggested and that did not work.........still showing year with 4 digits and not 2

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: change date format of date variable to something like 3/17/14

    I suggest you should the variable to date. If this does not make any difference, we need to see what kind of data you are working on.

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    ok will try that and let you know......back in a hour

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,017

    Re: change date format of date variable to something like 3/17/14

    What type of variable is junk1?
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    ok back........what i found works is the following......well it worked in a test file anyway......

    Please Login or Register  to view this content.
    i then use the yr_txt and day_txt and Mnth_2Digit variables concatented in a string and i get what i want.....

  10. #10
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    ok....it worked and didnt work........when i paste into sheet it converts it from 10/14/14 to 10/14/2014..........not sure why

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: change date format of date variable to something like 3/17/14

    Have you tried Excel's formatting functions? If it worked, but not now, it may be to do with formatting in new sheet.
    What types of variables are you declaring?

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,017

    Re: change date format of date variable to something like 3/17/14

    If you want it formatted in the sheet, format the cell, not the variable.

  13. #13
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    the variables i have tried as a date and variant.........i have a text string of "10/14/14" but when i place it into a cell it becomes 10/14/2014.

  14. #14
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    the variables i have tried as a date and variant.........i have a text string of "10/14/14" but when i place it into a cell it becomes 10/14/2014.

  15. #15
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: change date format of date variable to something like 3/17/14

    ok....this seems to work.........

    Please Login or Register  to view this content.
    not sure why....i think its because i formatted the cell first.........

  16. #16
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: change date format of date variable to something like 3/17/14

    Yes, that was my thought. The cells you are pasting might been formatted as "Text"

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,017

    Re: change date format of date variable to something like 3/17/14

    Why convert it to text? Store it as a date and format the cell:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need vba code to change date&time stamp as date format dd-mmm-yy in A:A rng
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2014, 06:08 AM
  2. How to change a unchageable date cell into a desired date format
    By erickwy in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-22-2014, 06:26 PM
  3. Macro to change date value from one date format to another date format
    By RG12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2013, 04:51 AM
  4. Not able to change date format into proper excel date format
    By excel5111987 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2011, 08:19 AM
  5. Replies: 3
    Last Post: 10-28-2010, 07:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1