Viewing 9 posts - 1 through 9 (of 9 total)
  • coding: convert date and time to words
  • technicallyinept
    Free Member

    Anyone? (c# or vb) My Google fu is weak today.

    nbt
    Full Member

    Date time d = date time.now
    String s = d.toshortdatestring()

    I think. No google was involved in the making of this post

    technicallyinept
    Free Member

    No, I mean actual words e.g 31/05/2015 would be may thirty first twenty fifteen.

    Have just found some suggestions to hard code an array of lookup words, seeing as there aren’t that many

    gary
    Full Member

    Various built in format options for DateTime.ToString(format), or you can roll your own.

    All here : https://msdn.microsoft.com/en-us/library/zdtaw1bw%28v=vs.110%29.aspx

    Links at the bottom of the page for more info on format strings.

    (Edit, but not read closely enough to see if it will do all words as in your example)

    technicallyinept
    Free Member

    I familiar with that, there is nothing for converting the day (number, not day of the week).

    This is for a recorded phone message.

    I’ve been asked for a ‘phonetic’ date. It could be that, eg ‘May 31 2015 at 5pm’ works.

    lemonysam
    Free Member

    Bit of a strange one, be easy to write a method for breaking the DateTime up into bits then using something like http://stackoverflow.com/questions/2729752/converting-numbers-in-to-words-c-sharp to convert the bits there’s not a string format method for.

    gary
    Full Member

    If you’re just going to hand it off to some kind of text->speech engine then yes, you would rather hope it would have its own support for numbers.

    But if not then yes, you will probably have to roll your own as above

    llama
    Full Member

    This better not be another help me with my coursework because I have not paid attention thread

    First I’m surprised that a text 2 speech thing won’t know to say ‘thirty first’ rather than ‘three one’

    Anyway, easiest way is probably a whole load of switch statements for each date time component you want to output

    technicallyinept
    Free Member

    It’s not coursework, just incompletely explained requirements for a rush job. It pretty much just says ‘write phonetic date here’. I’m gonna assume I just need to use the word for the month for now. No doubt I’ll be wrong!

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘coding: convert date and time to words’ is closed to new replies.